From 5c7f62cd535ca087fbb38f3ed1d519d98abc89c8 Mon Sep 17 00:00:00 2001 From: Aymeric Wibo Date: Fri, 20 Dec 2024 22:25:58 +0100 Subject: [PATCH] deps: Fix UB with zero-length VLAs --- src/dep_tree.c | 2 +- src/deps.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/dep_tree.c b/src/dep_tree.c index 8e4ce9fc..85aacdb8 100644 --- a/src/dep_tree.c +++ b/src/dep_tree.c @@ -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]; diff --git a/src/deps.c b/src/deps.c index 0224bab4..f92aafec 100644 --- a/src/deps.c +++ b/src/deps.c @@ -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);