Skip to content

Commit

Permalink
fix(fe): fix buffer overflow during keyword checking
Browse files Browse the repository at this point in the history
  • Loading branch information
strager committed Feb 25, 2024
1 parent d010165 commit 02a1c89
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ Semantic Versioning.

* TypeScript: `(): RT<T>=>null` (with no spaces in `>=>`) now parses correctly.
(Fixed by [vegerot][].)
* Fixed a read buffer overflow (possibly leading to a crash) when checking
whether short identifiers containing Unicode escape sequences are keywords.
(x86 and x86_64 only.) (Reported by [Roland Strasser][].)

## 3.1.0 (2024-01-10)

Expand Down
9 changes: 8 additions & 1 deletion src/quick-lint-js/fe/lex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <quick-lint-js/diag/buffering-diag-reporter.h>
#include <quick-lint-js/diag/diag-list.h>
#include <quick-lint-js/diag/diagnostic-types.h>
#include <quick-lint-js/fe/keyword-lexer.h>
#include <quick-lint-js/fe/lex.h>
#include <quick-lint-js/fe/token.h>
#include <quick-lint-js/port/bit.h>
Expand Down Expand Up @@ -1832,9 +1833,15 @@ Lexer::Parsed_Identifier Lexer::parse_identifier_slow(
}
}

String8_View normalized_view = normalized.release_to_string_view();

// Add padding bytes required by Keyword_Lexer. This should not be considered
// part of the returned string.
normalized.resize(normalized.size() + Keyword_Lexer::padding_size);

return Parsed_Identifier{
.after = input,
.normalized = normalized.release_to_string_view(),
.normalized = normalized_view,
.escape_sequences = escape_sequences,
};
}
Expand Down

0 comments on commit 02a1c89

Please sign in to comment.