@@ -277,6 +277,8 @@ token_t lex_token_internal(bool aliasing)
277277 int i = 0 ;
278278
279279 do {
280+ if (i >= MAX_TOKEN_LEN - 1 )
281+ error ("Token too long" );
280282 token_str [i ++ ] = next_char ;
281283 } while (is_alnum (read_char (false)));
282284 token_str [i ] = 0 ;
@@ -328,30 +330,40 @@ token_t lex_token_internal(bool aliasing)
328330
329331 if (is_digit (next_char )) {
330332 int i = 0 ;
333+ if (i >= MAX_TOKEN_LEN - 1 )
334+ error ("Token too long" );
331335 token_str [i ++ ] = next_char ;
332336 read_char (false);
333337
334338 if (token_str [0 ] == '0' && ((next_char | 32 ) == 'x' )) {
335339 /* Hexadecimal: starts with 0x or 0X */
340+ if (i >= MAX_TOKEN_LEN - 1 )
341+ error ("Token too long" );
336342 token_str [i ++ ] = next_char ;
337343
338344 read_char (false);
339345 if (!is_hex (next_char ))
340346 error ("Invalid hex literal: expected hex digit after 0x" );
341347
342348 do {
349+ if (i >= MAX_TOKEN_LEN - 1 )
350+ error ("Token too long" );
343351 token_str [i ++ ] = next_char ;
344352 } while (is_hex (read_char (false)));
345353
346354 } else if (token_str [0 ] == '0' && ((next_char | 32 ) == 'b' )) {
347355 /* Binary: starts with 0b or 0B */
356+ if (i >= MAX_TOKEN_LEN - 1 )
357+ error ("Token too long" );
348358 token_str [i ++ ] = next_char ;
349359
350360 read_char (false);
351361 if (next_char != '0' && next_char != '1' )
352362 error ("Invalid binary literal: expected 0 or 1 after 0b" );
353363
354364 do {
365+ if (i >= MAX_TOKEN_LEN - 1 )
366+ error ("Token too long" );
355367 token_str [i ++ ] = next_char ;
356368 read_char (false);
357369 } while (next_char == '0' || next_char == '1' );
@@ -361,13 +373,17 @@ token_t lex_token_internal(bool aliasing)
361373 while (is_digit (next_char )) {
362374 if (next_char >= '8' )
363375 error ("Invalid octal digit: must be in range 0-7" );
376+ if (i >= MAX_TOKEN_LEN - 1 )
377+ error ("Token too long" );
364378 token_str [i ++ ] = next_char ;
365379 read_char (false);
366380 }
367381
368382 } else {
369383 /* Decimal */
370384 while (is_digit (next_char )) {
385+ if (i >= MAX_TOKEN_LEN - 1 )
386+ error ("Token too long" );
371387 token_str [i ++ ] = next_char ;
372388 read_char (false);
373389 }
@@ -492,6 +508,8 @@ token_t lex_token_internal(bool aliasing)
492508 token_str [i - 1 ] = next_char ;
493509 }
494510 } else {
511+ if (i >= MAX_TOKEN_LEN - 1 )
512+ error ("String literal too long" );
495513 token_str [i ++ ] = next_char ;
496514 }
497515 if (next_char == '\\' )
@@ -744,6 +762,8 @@ token_t lex_token_internal(bool aliasing)
744762 char * alias ;
745763 int i = 0 ;
746764 do {
765+ if (i >= MAX_TOKEN_LEN - 1 )
766+ error ("Token too long" );
747767 token_str [i ++ ] = next_char ;
748768 } while (is_alnum (read_char (false)));
749769 token_str [i ] = 0 ;
0 commit comments