Skip to content

Commit d535753

Browse files
bugfix: nginx crashed when binding local address failed from lua.
* bugfix: nginx crashed when binding local address failed from lua. 0 0x00007f10b0b16c59 in __memcpy_ssse3_back () from /lib64/libc.so.6 1 0x000000000042e2ba in ngx_sprintf_str (buf=<optimized out>, last=last@entry=0x7fff82779250 "P\251#\002", src=<optimized out>, len=192, hexadecimal=hexadecimal@entry=0) at src/core/ngx_string.c:586 2 0x000000000042e824 in ngx_vslprintf (buf=<optimized out>, buf@entry=0x7fff82778279 "bind() failed (\347(G\300\a", last=last@entry=0x7fff82779250 "P\251#\002", fmt=0x59c7fc "V) failed", fmt@entry=0x59c7f6 "bind(%V) failed", args=args@entry=0x7fff82779258) at src/core/ngx_string.c:255 3 0x000000000042a243 in ngx_log_error_core (level=level@entry=3, log=log@entry=0x2263360, err=98, fmt=fmt@entry=0x59c7f6 "bind(%V) failed") at src/core/ngx_log.c:137 4 0x000000000044c4fc in ngx_event_connect_peer (pc=pc@entry=0x223a950) at src/event/ngx_event_connect.c:169 5 0x000000000049af8c in ngx_http_upstream_connect (r=r@entry=0x22923b0, u=u@entry=0x223a940) at src/http/ngx_http_upstream.c:1562 6 0x000000000049c410 in ngx_http_upstream_init_request (r=r@entry=0x22923b0) at src/http/ngx_http_upstream.c:826 7 0x000000000049ee79 in ngx_http_upstream_init (r=0x22923b0) at src/http/ngx_http_upstream.c:554 8 0x00000000004906ad in ngx_http_read_client_request_body (r=r@entry=0x22923b0, post_handler=0x49ed31 <ngx_http_upstream_init>) at src/http/ngx_http_request_body.c:47 9 0x00000000004dba84 in ngx_http_proxy_handler (r=0x22923b0) at src/http/modules/ngx_http_proxy_module.c:1023 10 0x00000000004822f4 in ngx_http_core_content_phase (r=0x22923b0, ph=<optimized out>) at src/http/ngx_http_core_module.c:1271 11 0x000000000047cb13 in ngx_http_core_run_phases (r=0x22923b0) at src/http/ngx_http_core_module.c:885 12 0x000000000047cc1e in ngx_http_handler (r=<optimized out>) at src/http/ngx_http_core_module.c:868 13 0x0000000000485f0e in ngx_http_run_posted_requests (c=c@entry=0x227c8f0) at src/http/ngx_http_request.c:2470 14 0x0000000000488b8b in ngx_http_process_request_headers (rev=rev@entry=0x22204f0) at src/http/ngx_http_request.c:1552 15 0x0000000000488e83 in ngx_http_process_request_line (rev=rev@entry=0x22204f0) at src/http/ngx_http_request.c:1196 16 0x0000000000489b82 in ngx_http_keepalive_handler (rev=0x22204f0) at src/http/ngx_http_request.c:3441 17 0x00000000004556e1 in ngx_epoll_process_events (cycle=0x2213ce0, timer=<optimized out>, flags=<optimized out>) at src/event/modules/ngx_epoll_module.c:901 18 0x000000000044a286 in ngx_process_events_and_timers (cycle=cycle@entry=0x2213ce0) at src/event/ngx_event.c:258 19 0x00000000004546a1 in ngx_single_process_cycle (cycle=cycle@entry=0x2213ce0) at src/os/unix/ngx_process_cycle.c:323 20 0x0000000000429793 in main (argc=<optimized out>, argv=<optimized out>) at src/core/nginx.c:384
1 parent 29fe7a5 commit d535753

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/ngx_http_lua_balancer.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,7 @@ ngx_http_lua_ffi_balancer_bind_to_local_addr(ngx_http_request_t *r,
994994
bp = (ngx_http_lua_balancer_peer_data_t *) u->peer.data;
995995

996996
if (bp->local == NULL) {
997-
bp->local = ngx_palloc(r->pool, sizeof(ngx_addr_t));
997+
bp->local = ngx_palloc(r->pool, sizeof(ngx_addr_t) + addr_len);
998998
if (bp->local == NULL) {
999999
p = ngx_snprintf(errbuf, *errbuf_size, "no memory");
10001000
*errbuf_size = p - errbuf;
@@ -1009,6 +1009,10 @@ ngx_http_lua_ffi_balancer_bind_to_local_addr(ngx_http_request_t *r,
10091009
return NGX_ERROR;
10101010
}
10111011

1012+
bp->local->name.len = addr_len;
1013+
bp->local->name.data = (u_char *) (bp->local + 1);
1014+
ngx_memcpy(bp->local->name.data, addr, addr_len);
1015+
10121016
return NGX_OK;
10131017
}
10141018

0 commit comments

Comments
 (0)