stb icon indicating copy to clipboard operation
stb copied to clipboard

stb_c_lexer crash

Open louisliangjun opened this issue 3 years ago • 4 comments

crash when parse source NOT endswith newline.

// main helper function for returning a parsed token static int stb__clex_token(stb_lexer *lexer, int token, char *start, char *end) { lexer->token = token; lexer->where_firstchar = start; lexer->where_lastchar = end; lexer->parse_point = end+1; <---- here, fix ----> (end == lexer->eof) ? end : end+1 return 1; }

louisliangjun avatar Mar 25 '21 02:03 louisliangjun

Ugh, it looks like stb_c_lexer has never actually been tested on non-NUL-terminated input strings, and has buffer overruns in most paths when handed such an input.

Until this is resolved, I would recommend only using stb_c_lexer on inputs that have a terminating NUL added.

rygorous avatar Jul 03 '21 00:07 rygorous

My test already used NUL-terminated string... it maybe another bug

louisliangjun avatar Jul 09 '21 12:07 louisliangjun

Yes, you're right, I think it's just the bug you describe in stb__clex_token.

nothings avatar Jul 09 '21 13:07 nothings

I would like to work on that, is there already a pull request on that? If not, is there anything else I should keep in mind?

johnmanthop avatar Jan 27 '22 17:01 johnmanthop