Skip to content

Commit

Permalink
deps: Fix UB with zero-length VLAs
Browse files Browse the repository at this point in the history
  • Loading branch information
obiwac committed Dec 20, 2024
1 parent 6e4d5ca commit 5c7f62c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/dep_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ dep_node_t* deps_tree(flamingo_val_t* deps_vec, size_t path_len, uint64_t* path_

build_tree:;

uint64_t hashes[deps_vec->vec.count];
uint64_t hashes[deps_vec->vec.count + 1]; // XXX +1 just so we don't get UB for zero-length VLAs.

for (size_t i = 0; i < deps_vec->vec.count; i++) {
dep_t* const dep = &deps[i];
Expand Down
4 changes: 2 additions & 2 deletions src/deps.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ int deps_build(dep_node_t* tree) {
size_t max_child_count = tree->child_count;
size_t const total_child_count = reset_built_deps(tree, &max_child_count);

char* already_built[total_child_count];
char* already_built[total_child_count + 1]; // XXX +1 because zero-length VLA UB.
size_t already_built_count = 0;

for (;;) {
char* leaves[max_child_count];
char* leaves[max_child_count + 1]; // XXX +1 because zero-length VLA UB.
size_t leaf_count = 0;

next_batch(tree, leaves, &leaf_count, already_built, &already_built_count);
Expand Down

0 comments on commit 5c7f62c

Please sign in to comment.