fix(scanner): buffer overflow & memory leak
Some checks failed
Publish package / npm (push) Has been cancelled
Publish package / crates (push) Has been cancelled
Publish package / pypi (push) Has been cancelled

This commit is contained in:
Amaan Qureshi 2024-04-10 00:01:08 -04:00
parent 4e516a7cd5
commit 3975596d84
2 changed files with 12 additions and 8 deletions

View file

@ -17,7 +17,7 @@ indent_size = 2
[*.{c,cc,h}] [*.{c,cc,h}]
indent_style = space indent_style = space
indent_size = 2 indent_size = 4
[*.rs] [*.rs]
indent_style = space indent_style = space

View file

@ -253,7 +253,9 @@ static inline bool is_wht(int32_t c) { return is_wsp(c) || is_nwl(c) || c == 0;
static inline bool is_ns_dec_digit(int32_t c) { return c >= '0' && c <= '9'; } static inline bool is_ns_dec_digit(int32_t c) { return c >= '0' && c <= '9'; }
static inline bool is_ns_hex_digit(int32_t c) { return is_ns_dec_digit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'); } static inline bool is_ns_hex_digit(int32_t c) {
return is_ns_dec_digit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
}
static inline bool is_ns_word_char(int32_t c) { static inline bool is_ns_word_char(int32_t c) {
return c == '-' || (c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); return c == '-' || (c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
@ -799,7 +801,7 @@ static bool scan(Scanner *scanner, TSLexer *lexer, const bool *valid_symbols) {
bool allow_comment = !(valid_symbols[R_DQT_STR_CTN] || valid_symbols[BR_DQT_STR_CTN] || bool allow_comment = !(valid_symbols[R_DQT_STR_CTN] || valid_symbols[BR_DQT_STR_CTN] ||
valid_symbols[R_SQT_STR_CTN] || valid_symbols[BR_SQT_STR_CTN]); valid_symbols[R_SQT_STR_CTN] || valid_symbols[BR_SQT_STR_CTN]);
int16_t *ind_ptr = scanner->ind_len_stk.contents + scanner->ind_len_stk.size - 1; int16_t *ind_ptr = scanner->ind_len_stk.contents + scanner->ind_len_stk.size - 1;
int16_t *ind_end = scanner->ind_len_stk.contents; int16_t *ind_end = scanner->ind_len_stk.contents - 1;
int16_t cur_ind = *ind_ptr--; int16_t cur_ind = *ind_ptr--;
int16_t prt_ind = ind_ptr == ind_end ? -1 : *ind_ptr; int16_t prt_ind = ind_ptr == ind_end ? -1 : *ind_ptr;
int16_t cur_ind_typ = *array_back(&scanner->ind_typ_stk); int16_t cur_ind_typ = *array_back(&scanner->ind_typ_stk);
@ -1364,6 +1366,8 @@ void *tree_sitter_yaml_external_scanner_create() {
void tree_sitter_yaml_external_scanner_destroy(void *payload) { void tree_sitter_yaml_external_scanner_destroy(void *payload) {
Scanner *scanner = (Scanner *)payload; Scanner *scanner = (Scanner *)payload;
array_delete(&scanner->ind_len_stk);
array_delete(&scanner->ind_typ_stk);
ts_free(scanner); ts_free(scanner);
} }