#5629: fail with ExFailure on scanf format ending in dangling %#5638
Merged
Conversation
|
Contributor
|
|
@morphqdd Thanks for the contribution! You've earned +16 points. Please, keep them coming. Your running score is +1274; don't forget to check your Zerocracy account too). |
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.



Closes #5629.
EOscanf.lambda()builds the match regex in a first loop, where a trailing lone%setsliteral = trueand appends nothing, without raising any error for the dangling, never-completed specifier. The extraction loop then locates that%viafrmt.indexOf('%')and reads the following char withfrmt.charAt(idx + 1). When the%is the last character of the format,idx + 1 == frmt.length(), and a rawjava.lang.StringIndexOutOfBoundsExceptionescapes instead of a properExFailure.This adds a check right after the first loop: if
literalis stilltrueonce the loop ends, the format string has a dangling%with no specifier after it, so it now fails fast with a clearExFailure, matching the existing pattern used for an unsupported specifier (thedefault:branch a few lines above).Added
EOscanfTest(a Java unit test assertingExFailureis thrown forscanf "hello%" "hello") and a--> on-scanf-with-dangling-percentEO-level example inscanf.eo, next to the two existingon-scanf-with-*negative examples for this object.Verified locally: the new tests pass,
EOstringTest(51 tests) and the generatedEOscanfEOAtomTest(15 tests, including the new example) pass, and qulice is clean.