]> Kevux Git Server - controller/commitdiff
Security: Potential buffer overflow on 0 length array.
authorKevin Day <kevin@kevux.org>
Thu, 9 May 2024 01:51:11 +0000 (20:51 -0500)
committerKevin Day <kevin@kevux.org>
Thu, 9 May 2024 01:51:11 +0000 (20:51 -0500)
The length_name_item variable can potentially be zero.
The assignment of "name_item[length_name_item] = 0;" will then result in an assignment on a 0 length array.

This issue has been exposed via GCC's -fanalyzer.

sources/c/main/rule/setting.c

index d7086a083fe78a9d19209bf2d31e7baa9613d6e0..a717c8ddc5c4c4dda18fb777256f685231bb8b4d 100644 (file)
@@ -40,7 +40,7 @@ extern "C" {
     const f_number_unsigned_t line_item = cache->action.line_item;
     const f_number_unsigned_t length_name_item = cache->action.name_item.used;
 
-    f_char_t name_item[length_name_item];
+    f_char_t name_item[length_name_item + 1];
     name_item[length_name_item] = 0;
 
     memcpy(name_item, cache->action.name_item.string, sizeof(f_char_t) * length_name_item);