fix: avoid out-of-bounds read when parsing the response status line#2464
Open
iliaal wants to merge 1 commit into
Open
fix: avoid out-of-bounds read when parsing the response status line#2464iliaal wants to merge 1 commit into
iliaal wants to merge 1 commit into
Conversation
frankenphp_send_headers parsed the status code with
atoi(SG(sapi_headers).http_status_line + 9), assuming a fixed
"HTTP/x.y " 9-byte prefix. A script setting a shorter status line, e.g.
header("HTTP/"), leaves http_status_line only 5 bytes long, so the +9
offset reads past the buffer. Confirmed with AddressSanitizer
(heap-buffer-overflow read in atoi, 3 bytes past a 6-byte estrndup'd
region) via an embed build with USE_ZEND_ALLOC=0.
PHP already parses the code into http_response_code through
sapi_update_response_code() whenever a status line is set, so the
reparse was redundant as well as unsafe. Use http_response_code
directly.
dunglas
approved these changes
Jun 4, 2026
alexandre-daubois
approved these changes
Jun 4, 2026
henderkes
approved these changes
Jun 4, 2026
dunglas
approved these changes
Jun 4, 2026
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.
frankenphp_send_headersparsed the status withatoi(http_status_line + 9), assuming a fixed 9-byte"HTTP/x.y "prefix.header("HTTP/")(5 bytes) makes+9read past the buffer. ASan confirms a heap-buffer-overflow read inatoi, 3 bytes past theestrndup'd line.PHP already parses the code into
http_response_code(viasapi_update_response_code()), so the reparse was redundant and unsafe. Use it directly. Tests instatusline_test.go(run under-asan) cover the short line and a validHTTP/1.1 418line.