-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix buffer overflow in argument parsing caused by lexer returning length beyond length of string #979
Merged
Conversation
This file contains 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
Signed-off-by: Shane Loretz <sloretz@openrobotics.org>
Signed-off-by: Shane Loretz <sloretz@openrobotics.org>
Signed-off-by: Shane Loretz <sloretz@openrobotics.org>
Signed-off-by: Shane Loretz <sloretz@openrobotics.org>
ivanpauno
approved these changes
Apr 18, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not super familiar with this code, but this seems reasonable to me
delete-merged-branch
bot
deleted the
sloretz__asan_lexer_buffer_overflow
branch
April 18, 2022 17:31
@Mergifyio backport galactic foxy |
mergify bot
pushed a commit
that referenced
this pull request
Apr 19, 2022
…gth beyond length of string (#979) * Test that lexer never returns length longer than string Signed-off-by: Shane Loretz <sloretz@openrobotics.org> * Fix bug where lexer returned length longer than string Signed-off-by: Shane Loretz <sloretz@openrobotics.org> * Test that peeking 2 ahead never goes beyond NONE or EOF Signed-off-by: Shane Loretz <sloretz@openrobotics.org> * Stop peeking if the first lexeme is NONE or EOF Signed-off-by: Shane Loretz <sloretz@openrobotics.org> (cherry picked from commit 392f0d3)
mergify bot
pushed a commit
that referenced
this pull request
Apr 19, 2022
…gth beyond length of string (#979) * Test that lexer never returns length longer than string Signed-off-by: Shane Loretz <sloretz@openrobotics.org> * Fix bug where lexer returned length longer than string Signed-off-by: Shane Loretz <sloretz@openrobotics.org> * Test that peeking 2 ahead never goes beyond NONE or EOF Signed-off-by: Shane Loretz <sloretz@openrobotics.org> * Stop peeking if the first lexeme is NONE or EOF Signed-off-by: Shane Loretz <sloretz@openrobotics.org> (cherry picked from commit 392f0d3)
✅ Backports have been created
|
clalancette
pushed a commit
that referenced
this pull request
May 17, 2022
…gth beyond length of string (#979) (#980) * Test that lexer never returns length longer than string Signed-off-by: Shane Loretz <sloretz@openrobotics.org> * Fix bug where lexer returned length longer than string Signed-off-by: Shane Loretz <sloretz@openrobotics.org> * Test that peeking 2 ahead never goes beyond NONE or EOF Signed-off-by: Shane Loretz <sloretz@openrobotics.org> * Stop peeking if the first lexeme is NONE or EOF Signed-off-by: Shane Loretz <sloretz@openrobotics.org> (cherry picked from commit 392f0d3) Co-authored-by: Shane Loretz <sloretz@openrobotics.org>
clalancette
pushed a commit
that referenced
this pull request
May 17, 2022
…gth beyond length of string (#979) (#981) * Test that lexer never returns length longer than string Signed-off-by: Shane Loretz <sloretz@openrobotics.org> * Fix bug where lexer returned length longer than string Signed-off-by: Shane Loretz <sloretz@openrobotics.org> * Test that peeking 2 ahead never goes beyond NONE or EOF Signed-off-by: Shane Loretz <sloretz@openrobotics.org> * Stop peeking if the first lexeme is NONE or EOF Signed-off-by: Shane Loretz <sloretz@openrobotics.org> (cherry picked from commit 392f0d3) Co-authored-by: Shane Loretz <sloretz@openrobotics.org>
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.
While running
rcl
's tests under address sanitizer I noticed a buffer overflow in test_arguments here:rcl/rcl/test/rcl/test_arguments.cpp
Line 239 in 71baed4
Address sanitizer output in test
The lexer tries to match the lexeme TILDE_SLASH, but fails because the end of the string is reached. When matching a lexeme fails, the lexer uses a default transition to T_NONE. This transition increases the length of the lexeme by 1, with the idea being to make the length include the character which caused no lexeme to be found so it can be included in error messages. This behavior is a problem when the end of the string is reached, because any code trying to access the problematic string now reads 1 past the end of the string.
In this particular case,
rcl_lexer_lookahead2_peek2()
caused the overflow by trying to read a second lexeme starting at one past the end of the string.This PR fixes the buffer overflow in two ways. First it makes sure the lexer never returns a length beyond the length of the string. Second, it makes
rcl_lexer_lookahead2_peek2()
stop peeking at the string if the first peek is NONE or EOF.