From 96abf202e4b915df6e17ec23fc2fe2047f84b56e Mon Sep 17 00:00:00 2001 From: "Yichun Zhang (agentzh)" Date: Wed, 10 Jul 2013 13:13:57 -0700 Subject: [PATCH] bugfix: we did not initialize c->addr_text properly in nginx-1.4.1-unix_socket_accept_over_read.patch. --- ...x-1.4.1-unix_socket_accept_over_read.patch | 46 +++++++++++++++---- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/patches/nginx-1.4.1-unix_socket_accept_over_read.patch b/patches/nginx-1.4.1-unix_socket_accept_over_read.patch index 2efdd56..ac8138c 100644 --- a/patches/nginx-1.4.1-unix_socket_accept_over_read.patch +++ b/patches/nginx-1.4.1-unix_socket_accept_over_read.patch @@ -1,11 +1,41 @@ --- nginx-1.4.1/src/event/ngx_event_accept.c 2013-05-06 03:26:50.000000000 -0700 -+++ nginx-1.4.1-patched/src/event/ngx_event_accept.c 2013-07-09 17:41:42.688468839 -0700 -@@ -268,7 +268,7 @@ ngx_event_accept(ngx_event_t *ev) - wev->own_lock = &c->lock; ++++ nginx-1.4.1-patched/src/event/ngx_event_accept.c 2013-07-10 13:05:02.001249099 -0700 +@@ -269,17 +269,28 @@ ngx_event_accept(ngx_event_t *ev) #endif -- if (ls->addr_ntop) { -+ if (ls->addr_ntop && socklen > sizeof(c->sockaddr->sa_family)) { - c->addr_text.data = ngx_pnalloc(c->pool, ls->addr_text_max_len); - if (c->addr_text.data == NULL) { - ngx_close_accepted_connection(c); + if (ls->addr_ntop) { +- c->addr_text.data = ngx_pnalloc(c->pool, ls->addr_text_max_len); +- if (c->addr_text.data == NULL) { +- ngx_close_accepted_connection(c); +- return; +- } ++ if (socklen > sizeof(c->sockaddr->sa_family)) { ++ c->addr_text.data = ngx_pnalloc(c->pool, ls->addr_text_max_len); ++ if (c->addr_text.data == NULL) { ++ ngx_close_accepted_connection(c); ++ return; ++ } ++ ++ c->addr_text.len = ngx_sock_ntop(c->sockaddr, c->addr_text.data, ++ ls->addr_text_max_len, 0); ++ if (c->addr_text.len == 0) { ++ ngx_close_accepted_connection(c); ++ return; ++ } ++ ++ } else { ++ /* ++ * Linux accept/accept4 syscalls, for example, do not return ++ * address data upon unix domain sockets ++ */ + +- c->addr_text.len = ngx_sock_ntop(c->sockaddr, c->addr_text.data, +- ls->addr_text_max_len, 0); +- if (c->addr_text.len == 0) { +- ngx_close_accepted_connection(c); +- return; ++ c->addr_text.data = NULL; ++ c->addr_text.len = 0; + } + } +