Skip to content
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 out-of-bounds read in statement tail parser #996

Merged
merged 3 commits into from
May 2, 2023

Conversation

arimah
Copy link
Contributor

@arimah arimah commented Apr 25, 2023

Fixes #975

I would love to include a regression test with this PR, but as the problem only occurs when reading random noise past the end of a string, I have no idea how to accomplish such a feat.

@arimah arimah requested a review from JoshuaWise as a code owner April 25, 2023 06:36
mceachen
mceachen previously approved these changes Apr 25, 2023
Copy link
Member

@mceachen mceachen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. This codebase doesn't have this tradition, but I've found it super handy to add a link to the issue (say, right before line 862) explaining the exotic/missing-incr for loop.

@Prinzhorn does this PR make your random-failure test harness pass?

mceachen
mceachen previously approved these changes Apr 25, 2023
@Prinzhorn
Copy link
Contributor

@kkrypt0nn can you verify this locally? Does it fix the randomness for you? I can't look into this rn.

kkrypt0nn
kkrypt0nn previously approved these changes Apr 26, 2023
Copy link

@kkrypt0nn kkrypt0nn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally with similar code as in my comment in the issue. Result was consistent and working as expected.

Many thanks for your 🔥 investigation @arimah

@arimah
Copy link
Contributor Author

arimah commented Apr 26, 2023

Happy to help! 😄 Hope we can get this merged and released soon – just need code owner review too 👀

@mceachen
Copy link
Member

@JoshuaWise can you take a look please?

@JoshuaWise
Copy link
Member

JoshuaWise commented Apr 27, 2023

Thanks for finding the source of this bug.

The only problem I see is that your solution breaks when there's a newline after -- or when there's a closed quote like /* foo */. My original code accounted for those cases by incrementing the pointer one less byte (knowing that the ++tail would be increment it again at the top of the loop), but I forgot to account for the cases where the inner loop terminates due to a nul byte. Your code accounts for the latter case, but not the --\n and /* foo */ cases.

Also, we should add tests for all of these cases 😅

@arimah
Copy link
Contributor Author

arimah commented Apr 27, 2023

Ahhhh, you're quite right, @JoshuaWise. These dang nested loops! We should be able to solve that by doing tail += 2; when a delimited comment ends, as well as adding an extra increment if we encounter \n inside a -- comment. I will update my code accordingly, and add a few tests for the cases you have just (rightly) pointed out.

@arimah arimah dismissed stale reviews from kkrypt0nn and mceachen via 800e16a April 27, 2023 20:31
@arimah arimah force-pushed the fix-statement-tail-parsing-975 branch from 800e16a to 5ba7d7c Compare April 27, 2023 20:32
@arimah arimah force-pushed the fix-statement-tail-parsing-975 branch from 5ba7d7c to 36cc72a Compare April 27, 2023 20:33
@arimah
Copy link
Contributor Author

arimah commented Apr 27, 2023

O-kay, I think that does it now. The tail parser should (touch wood) skip the right number of characters in the right places now, and I've added a variety of little test cases to that effect. Everything passes locally, let's hope the pipeline here concurs.

@mceachen @JoshuaWise Please have a look and maybe we can get this little bug fixed 🙏

@JoshuaWise
Copy link
Member

LGTM, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Result of query with comment is inconsistent and random
5 participants