Avoid UB trimming empty response header values - #749
Open
mcc0nnell wants to merge 1 commit into
Open
Conversation
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.
This avoids undefined behavior when trimming trailing whitespace from empty header values.
Several response/header parsing paths initialized the trim pointer with
&value[strlen(value) - 1](or the equivalentl + strlen(l) - 1). For an empty value, that constructs a pointer before the start of the string object before the loop condition can reject it.Use an end-exclusive pointer instead and only inspect
end[-1]whileend > value.Updated paths:
mod_proxy_httpmod_proxy_uwsgimod_proxy_hcheckserver/util_script.cmod_cern_metaThe proxy tests add backend responses containing a valid empty
X-Empty:header for both HTTP proxy and uWSGI paths.Validation against trunk
3ffb2beeb058fa88d0a7b0de8b93d21ac7ec5f66:test_03_response.py+test_05_uwsgi.py: 6/6 passedgit diff --check: cleanA small Clang UBSan/pointer-overflow reproducer also reports the original empty-value expression and is silent with the end-exclusive form.
I have not demonstrated a crash, out-of-bounds read/write, information disclosure, or other exploit primitive; this is a narrow UB hardening change.