fix(static): add missing enum sentinel to ngx_http_zstd_static[]#74
Merged
Conversation
The ngx_http_zstd_static[] ngx_conf_enum_t array (off/on/always) lacked
the terminating { ngx_null_string, 0 } sentinel. ngx_conf_set_enum_slot()
scans the array with `for (i = 0; e[i].name.len != 0; i++)`, so an
unmatched directive value (e.g. `zstd_static maybe;`) walks off the end
of the array reading garbage name.len/name.data — an out-of-bounds read,
and ngx_strcasecmp() then dereferences a wild pointer (possible crash /
ASAN abort). Every stock nginx enum terminates with the sentinel; add it.
With the sentinel an unknown value is a clean "invalid value" config
error instead of undefined behaviour.
Tests (t/02-conf-warn.t): TEST 3 asserts an invalid enum value is
rejected with `invalid value "maybe"` (must_die); TEST 4 asserts the
last real entry "always" still parses. The ASAN CI job runs this binary,
so a re-introduced OOB read aborts on TEST 3.
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.
BLOCKER from module audit.
Problem
ngx_http_zstd_static[](theoff/on/alwaysngx_conf_enum_tarray) is missing the terminating{ ngx_null_string, 0 }sentinel.ngx_conf_set_enum_slot()scans withfor (i = 0; e[i].name.len != 0; i++), so an unmatched value such aszstd_static maybe;walks off the array end — an out-of-bounds read, after whichngx_strcasecmp()dereferences a wild pointer (possible crash / ASAN abort at config load).Fix
Add the sentinel. Every stock nginx enum carries it. Unknown values now produce a clean
invalid valueconfig error.Tests
t/02-conf-warn.tTEST 3 —zstd_static maybe;->must_diewithinvalid value "maybe"(the ASAN CI job aborts here if the OOB read returns).always(last real entry) still parses/loads.Local:
prove t/02-conf-warn.t= 11/11 PASS.