aboutsummaryrefslogtreecommitdiff
path: root/src/core/ngx_proxy_protocol.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/ngx_proxy_protocol.c')
-rw-r--r--src/core/ngx_proxy_protocol.c41
1 files changed, 37 insertions, 4 deletions
diff --git a/src/core/ngx_proxy_protocol.c b/src/core/ngx_proxy_protocol.c
index f347e7f43..3e54d4255 100644
--- a/src/core/ngx_proxy_protocol.c
+++ b/src/core/ngx_proxy_protocol.c
@@ -12,8 +12,9 @@
u_char *
ngx_proxy_protocol_read(ngx_connection_t *c, u_char *buf, u_char *last)
{
- size_t len;
- u_char ch, *p, *addr;
+ size_t len;
+ u_char ch, *p, *addr, *port;
+ ngx_int_t n;
p = buf;
len = last - buf;
@@ -71,8 +72,40 @@ ngx_proxy_protocol_read(ngx_connection_t *c, u_char *buf, u_char *last)
ngx_memcpy(c->proxy_protocol_addr.data, addr, len);
c->proxy_protocol_addr.len = len;
- ngx_log_debug1(NGX_LOG_DEBUG_CORE, c->log, 0,
- "PROXY protocol address: \"%V\"", &c->proxy_protocol_addr);
+ for ( ;; ) {
+ if (p == last) {
+ goto invalid;
+ }
+
+ if (*p++ == ' ') {
+ break;
+ }
+ }
+
+ port = p;
+
+ for ( ;; ) {
+ if (p == last) {
+ goto invalid;
+ }
+
+ if (*p++ == ' ') {
+ break;
+ }
+ }
+
+ len = p - port - 1;
+
+ n = ngx_atoi(port, len);
+
+ if (n < 0 || n > 65535) {
+ goto invalid;
+ }
+
+ c->proxy_protocol_port = (in_port_t) n;
+
+ ngx_log_debug2(NGX_LOG_DEBUG_CORE, c->log, 0,
+ "PROXY protocol address: %V %i", &c->proxy_protocol_addr, n);
skip: