Skip to content

Commit 9e2bb92

Browse files
casualjimMartin Vogel
authored andcommitted
fix(arena): NULL-arena guard in cbm_arena_alloc; skip vendored/ dirs
- cbm_arena_alloc returns NULL on a NULL arena (both arena.c copies) instead of dereferencing it — defense-in-depth against the NULL-arena type-allocation path that could crash the LSP type layer. - discover: add "vendored" to the always-skip directory list. Distilled from #374, taking the parts not already on main. The PR's ts_lsp tuple-arena allocation, the C/C++ template formal-count clamp, and the type_rep unbound-param preservation it also carried all landed independently in v0.7.0 / via #322 / #360, so only these two defensive improvements remain. Relates to #390.
1 parent 9bcfaab commit 9e2bb92

5 files changed

Lines changed: 15 additions & 3 deletions

File tree

‎internal/cbm/arena.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static int arena_grow(CBMArena *a, size_t min_size) {
3333
}
3434

3535
void *cbm_arena_alloc(CBMArena *a, size_t n) {
36-
if (n == 0) {
36+
if (!a || n == 0) {
3737
return NULL;
3838
}
3939
// 8-byte alignment

‎src/discover/discover.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static const char *ALWAYS_SKIP_DIRS[] = {
4444
/* Deploy */
4545
".vercel", ".netlify",
4646
/* Misc */
47-
".qdrant_code_embeddings", ".tmp", "vendor", NULL};
47+
".qdrant_code_embeddings", ".tmp", "vendor", "vendored", NULL};
4848

4949
static const char *FAST_SKIP_DIRS[] = {
5050
"generated", "gen", "auto-generated", "fixtures", "testdata", "test_data",

‎src/foundation/arena.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static int arena_grow(CBMArena *a, size_t min_size) {
5656
}
5757

5858
void *cbm_arena_alloc(CBMArena *a, size_t n) {
59-
if (n == 0) {
59+
if (!a || n == 0) {
6060
return NULL;
6161
}
6262
/* 8-byte alignment */

‎tests/test_arena.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ TEST(arena_alloc_zero) {
4545
PASS();
4646
}
4747

48+
TEST(arena_alloc_null_arena) {
49+
void *p = cbm_arena_alloc(NULL, 16);
50+
ASSERT_NULL(p);
51+
PASS();
52+
}
53+
4854
TEST(arena_alloc_alignment) {
4955
CBMArena a;
5056
cbm_arena_init(&a);
@@ -426,6 +432,7 @@ SUITE(arena) {
426432
RUN_TEST(arena_init_sized);
427433
RUN_TEST(arena_alloc_basic);
428434
RUN_TEST(arena_alloc_zero);
435+
RUN_TEST(arena_alloc_null_arena);
429436
RUN_TEST(arena_alloc_alignment);
430437
RUN_TEST(arena_alloc_grows_blocks);
431438
RUN_TEST(arena_alloc_large_single);

‎tests/test_discover.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ TEST(skip_vendor) {
3737
ASSERT_TRUE(cbm_should_skip_dir("vendor", CBM_MODE_FULL));
3838
PASS();
3939
}
40+
TEST(skip_vendored) {
41+
ASSERT_TRUE(cbm_should_skip_dir("vendored", CBM_MODE_FULL));
42+
PASS();
43+
}
4044
TEST(skip_terraform) {
4145
ASSERT_TRUE(cbm_should_skip_dir(".terraform", CBM_MODE_FULL));
4246
PASS();
@@ -680,6 +684,7 @@ SUITE(discover) {
680684
RUN_TEST(skip_dist);
681685
RUN_TEST(skip_target);
682686
RUN_TEST(skip_vendor);
687+
RUN_TEST(skip_vendored);
683688
RUN_TEST(skip_terraform);
684689
RUN_TEST(skip_coverage);
685690
RUN_TEST(skip_idea);

0 commit comments

Comments
 (0)