Skip to content

Commit 6071a42

Browse files
committed
Prevent buffer overflow in type array allocation
This commit adds bounds checking to add_type and increase MAX_TYPES to 128, fixing memory corruption during stage-1 compilation when typedef count exceeds limit.
1 parent f0e6325 commit 6071a42

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/defs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#define MAX_PARAMS 8
2020
#define MAX_LOCALS 1600
2121
#define MAX_FIELDS 64
22-
#define MAX_TYPES 64
22+
#define MAX_TYPES 128
2323
#define MAX_IR_INSTR 60000
2424
#define MAX_BB_PRED 128
2525
#define MAX_BB_DOM_SUCC 64

src/globals.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,10 @@ int find_macro_param_src_idx(char *name, block_t *parent)
721721

722722
type_t *add_type(void)
723723
{
724+
if (types_idx >= MAX_TYPES) {
725+
printf("Error: Maximum number of types (%d) exceeded\n", MAX_TYPES);
726+
abort();
727+
}
724728
return &TYPES[types_idx++];
725729
}
726730

0 commit comments

Comments
 (0)