From 818abecd2d85de92ea1f93ec9a628bee2712adcb Mon Sep 17 00:00:00 2001 From: christos chatzifountas Date: Wed, 31 Dec 2025 01:14:40 +0200 Subject: [PATCH 1/2] Update auto_dup --- clang/parse/auto_dup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/parse/auto_dup.c b/clang/parse/auto_dup.c index d0aacb92..bfac2f20 100644 --- a/clang/parse/auto_dup.c +++ b/clang/parse/auto_dup.c @@ -62,7 +62,7 @@ fn void auto_dup_go(u64 loc, u32 lvl, u32 base, u32 *use, u32 n, u32 lab, u8 tgt } // Shift outer refs - if ((tg == BJV || tg == BJ0 || tg == BJ1) && vl > base) { + if ((tg == BJV || tg == BJ0 || tg == BJ1 || tg == BJM) && vl > base) { HEAP[loc] = term_new(0, tg, term_ext(t), vl + n); return; } From ac4937c765d76c3f8c02884b8c29a3616d2b15d5 Mon Sep 17 00:00:00 2001 From: christos chatzifountas Date: Wed, 31 Dec 2025 06:46:16 +0200 Subject: [PATCH 2/2] fix: add null checks and bounds validation for memory safety MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add null check after strdup in parse_include - Add bounds check for string parsing (max 4096 codepoints) - Add null check after malloc in table_find 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- clang/parse/include.c | 6 +++++- clang/parse/term/str.c | 3 +++ clang/table/find.c | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/clang/parse/include.c b/clang/parse/include.c index 18d3d0fe..c90b7c1d 100644 --- a/clang/parse/include.c +++ b/clang/parse/include.c @@ -26,7 +26,11 @@ fn void parse_include(PState *s) { if (PARSE_SEEN_FILES_LEN >= 1024) { sys_error("MAX_INCLUDES"); } - PARSE_SEEN_FILES[PARSE_SEEN_FILES_LEN++] = strdup(path); + char *path_copy = strdup(path); + if (!path_copy) { + sys_error("out of memory in parse_include"); + } + PARSE_SEEN_FILES[PARSE_SEEN_FILES_LEN++] = path_copy; // Read and parse char *src = sys_file_read(path); diff --git a/clang/parse/term/str.c b/clang/parse/term/str.c index 3151f4aa..911f3958 100644 --- a/clang/parse/term/str.c +++ b/clang/parse/term/str.c @@ -13,6 +13,9 @@ fn Term parse_term_str(PState *s, u32 depth) { } else { c = parse_utf8(s); } + if (n >= 4096) { + parse_error(s, "string too long (max 4096 codepoints)", '"'); + } cs[n++] = c; } parse_advance(s); diff --git a/clang/table/find.c b/clang/table/find.c index 9867fbc3..a68c5e47 100644 --- a/clang/table/find.c +++ b/clang/table/find.c @@ -11,6 +11,9 @@ fn u32 table_find(const char *name, u32 len) { // Not found - create new entry u32 id = TABLE_LEN++; char *copy = malloc(len + 1); + if (!copy) { + sys_error("out of memory in table_find"); + } memcpy(copy, name, len); copy[len] = '\0'; TABLE[id] = copy;