Conversation
The capitalize function wrote result[0] and dereferenced result.begin()+1 unconditionally, so capitalize with an empty string indexed an empty std::string out of bounds and passed a malformed [begin()+1, end()) range to std::transform, segfaulting on valid template input. Guard the transform with a non-empty check; an empty argument now returns an empty string. Applied to both the modular header and the single-include amalgamation. Fixes pantor#337
Owner
|
Issue was resolved by #343. |
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.
Fixes #337.
Problem
{{ capitalize("") }}crashes. InRenderer::visit'sOp::Capitalizecase the code unconditionally writesresult[0]and dereferencesresult.begin() + 1:For an empty string
result[0]is out of bounds,result.begin() + 1is an invalid iterator, and the transform range[begin() + 1, end())is malformed (first > last). This is reachable from ordinary valid template input, socapitalize("")segfaults (a_GLIBCXX_DEBUGbuild aborts with "function requires a valid iterator range"; ASan reports a stack-buffer-overflow read).Fix
Guard the capitalization with a non-empty check; an empty argument returns
""(the reporter's expected behavior). Applied to bothinclude/inja/renderer.hppand thesingle_include/inja/inja.hppamalgamation.Test
Added
CHECK(env.render("{{ capitalize(\"\") }}", data) == "");to the existingcapitalizesubcase intest/test-functions.cpp. Red-green verified: before the fix the test binary segfaults (exit 139) at this case; after, all 15 test cases / 259 assertions pass, warning-clean under-Wall -Wextra.