Repository navigation
fix(gen): keep a full-speed scanner inside yy_transition after a NUL - #908
Merged
Merged
Conversation
A NUL in the input has the same equivalence class as the end-of-buffer character, so a -F/-CF scanner takes the end-of-buffer transition on it and lands on the state at the last entry of yy_transition. The scanning loop then indexes that state again with the class of the next character and reads past the table. Emit a jam for every class after that state in genctbl() and mkctbl(), so it jams for any class as it already did for the end-of-buffer one. Refs: westes#628
Since an <<EOF>> rule is reduced before the scanner has read its action, the directive and opening quote for it went in before we knew whether the action was '|'. A '|' rule has no action text of its own and so nothing closes that quote, and m4 stopped with "end of file in string". Emit them from the sect2 rule in parse.y instead, once the end of the rule has been read, and skip them for '|' as finish_rule() already does. tests/eof_continued.l covers an <<EOF>> rule with a '|' action both outside and inside a start condition. fixes westes#906
fast_nul only covers a scanner with its tables built in. A scanner that loads them from a tables file reads them from a separate block of memory, so the same read past the end of the table looks different. tests/fast_nul_tables.l gives such a scanner a NUL in its input and uses the allocator in tables_bad.h, which puts each block against an unreadable page, so a read past the table stops the test without a sanitizer. Refs: westes#628
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.
a NUL in the scanned input has the same equivalence class as the end-of-buffer character, so a -F/-CF scanner takes the end-of-buffer transition on it and lands on the state that
genctbl()andmkctbl()put atbase[lastdfa + 1] = tblend + 2, the last entry ofyy_transition. the scanning loop indexes a state once more after it has taken a transition, with the class of the next character, so it then readsyy_transition[tblend + 2 + yy_c]for any class from 1 up. both emitters say they assume the only character that can index that state is the end-of-buffer one, which holds at a real end of buffer, where a second end-of-buffer character follows, but not for a NUL in the middle of the input. scanninga b NUL c d \377 e fgives an ASan global-buffer-overflow READ inyylexwith inline tables and a heap-buffer-overflow with--tables-file, and an entry past the table that happens to matchyy_verifysendsyy_current_stateto an arbitrary offset. giving that state its missing jam entries keeps the change in the two places that lay out the table and leaves every existing entry alone, so these scanners jam there for any class as they already did for class 0, and count the same tokens as the compressed and full-table ones.tests/fast_nulfails before and passes after, without needing a sanitizer. the rest of the suite is unchanged here, including thetableoptsserialize and verify tests for every table option on the nr, r and c99 back ends, and flex still regenerates its own scanner bit-identically. C++ scanners are not affected, since flex refuses-+with-CF.Refs: #628