@@ -277,6 +277,8 @@ token_t lex_token_internal(bool aliasing)
277
277
int i = 0 ;
278
278
279
279
do {
280
+ if (i >= MAX_TOKEN_LEN - 1 )
281
+ error ("Token too long" );
280
282
token_str [i ++ ] = next_char ;
281
283
} while (is_alnum (read_char (false)));
282
284
token_str [i ] = 0 ;
@@ -328,30 +330,40 @@ token_t lex_token_internal(bool aliasing)
328
330
329
331
if (is_digit (next_char )) {
330
332
int i = 0 ;
333
+ if (i >= MAX_TOKEN_LEN - 1 )
334
+ error ("Token too long" );
331
335
token_str [i ++ ] = next_char ;
332
336
read_char (false);
333
337
334
338
if (token_str [0 ] == '0' && ((next_char | 32 ) == 'x' )) {
335
339
/* Hexadecimal: starts with 0x or 0X */
340
+ if (i >= MAX_TOKEN_LEN - 1 )
341
+ error ("Token too long" );
336
342
token_str [i ++ ] = next_char ;
337
343
338
344
read_char (false);
339
345
if (!is_hex (next_char ))
340
346
error ("Invalid hex literal: expected hex digit after 0x" );
341
347
342
348
do {
349
+ if (i >= MAX_TOKEN_LEN - 1 )
350
+ error ("Token too long" );
343
351
token_str [i ++ ] = next_char ;
344
352
} while (is_hex (read_char (false)));
345
353
346
354
} else if (token_str [0 ] == '0' && ((next_char | 32 ) == 'b' )) {
347
355
/* Binary: starts with 0b or 0B */
356
+ if (i >= MAX_TOKEN_LEN - 1 )
357
+ error ("Token too long" );
348
358
token_str [i ++ ] = next_char ;
349
359
350
360
read_char (false);
351
361
if (next_char != '0' && next_char != '1' )
352
362
error ("Invalid binary literal: expected 0 or 1 after 0b" );
353
363
354
364
do {
365
+ if (i >= MAX_TOKEN_LEN - 1 )
366
+ error ("Token too long" );
355
367
token_str [i ++ ] = next_char ;
356
368
read_char (false);
357
369
} while (next_char == '0' || next_char == '1' );
@@ -361,13 +373,17 @@ token_t lex_token_internal(bool aliasing)
361
373
while (is_digit (next_char )) {
362
374
if (next_char >= '8' )
363
375
error ("Invalid octal digit: must be in range 0-7" );
376
+ if (i >= MAX_TOKEN_LEN - 1 )
377
+ error ("Token too long" );
364
378
token_str [i ++ ] = next_char ;
365
379
read_char (false);
366
380
}
367
381
368
382
} else {
369
383
/* Decimal */
370
384
while (is_digit (next_char )) {
385
+ if (i >= MAX_TOKEN_LEN - 1 )
386
+ error ("Token too long" );
371
387
token_str [i ++ ] = next_char ;
372
388
read_char (false);
373
389
}
@@ -492,6 +508,8 @@ token_t lex_token_internal(bool aliasing)
492
508
token_str [i - 1 ] = next_char ;
493
509
}
494
510
} else {
511
+ if (i >= MAX_TOKEN_LEN - 1 )
512
+ error ("String literal too long" );
495
513
token_str [i ++ ] = next_char ;
496
514
}
497
515
if (next_char == '\\' )
@@ -744,6 +762,8 @@ token_t lex_token_internal(bool aliasing)
744
762
char * alias ;
745
763
int i = 0 ;
746
764
do {
765
+ if (i >= MAX_TOKEN_LEN - 1 )
766
+ error ("Token too long" );
747
767
token_str [i ++ ] = next_char ;
748
768
} while (is_alnum (read_char (false)));
749
769
token_str [i ] = 0 ;
0 commit comments