Repository navigation
Conversation
…d address. ngx_parse_addr_port() returns NGX_DECLINED when the text is not an address; NGX_ERROR only means an allocation failed. The FFI function only checked for NGX_ERROR, so an invalid address such as "not-an-ip" was reported as success, and an ngx_addr_t whose sockaddr was never set (it comes from ngx_palloc()) was published to bp->local. The upstream connect then called ngx_inet_get_port() and bind() on that pointer, and the worker exited on signal 11. Treat anything but NGX_OK as an invalid address and keep the previous bp->local, as ngx_stream_lua_ffi_balancer_bind_to_local_addr() already does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I hereby granted the copyright of the changes in this pull request
to the authors of this lua-nginx-module project.
ngx_parse_addr_port()returnsNGX_DECLINEDwhen the text is not an address;NGX_ERRORonly means an allocation failed.ngx_http_lua_ffi_balancer_bind_to_local_addr()only checks forNGX_ERROR:So
balancer.bind_to_local_addr("not-an-ip")returnstrue, and anngx_addr_twhosesockaddrwas never set (it comes fromngx_palloc()) is stored inbp->local.ngx_event_connect_peer()then callsngx_inet_get_port()andbind()on that pointer:The Lua wrapper only checks that the argument is a string, so any string that is not an address reaches this path, for example a typo in the configuration or an address taken from request data.
This change treats anything but
NGX_OKas an invalid address and keeps the previousbp->local, which is whatngx_stream_lua_ffi_balancer_bind_to_local_addr()already does. With it, the call returnsnil, "invalid addr not-an-ip"and the request goes on with the previously bound address.TEST 6 in
t/138-balancer-upstream-bind.tbinds127.0.0.2, then"not-an-ip", and expects the error to be logged and the upstream to see127.0.0.2. Without the fix the worker crashes and the test fails; with itt/138-balancer-upstream-bind.tpasses. Tested against nginx 1.31.1 in an OpenResty build; the function and the test file are the same as on master.