Skip to contentSkip to conversation

segtree: Fix for variable-sized object may not be initialized

PATCH In review Phil Sutter 2 participants 3 messages Mar 19 – Mar 20 netfilter

lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

PATCH 1/1 segtree: Fix for variable-sized object may not be initialized

Seen with gcc-11.5.0 on an aarch64 machine, build failed. Looking at the code, r1len (or r1->len, actually) really seems variable. So use memset() and fix build for that older compiler version at least.

Fixes e8b17865833b8 ("segtree: Fix range aggregation on Big Endian")
---
 src/segtree.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
src/segtree.c +2 -1
index bfea2f64ed812..a12820bcf1ece 100644
@@ -426,8 +426,9 @@ void concat_range_aggregate(struct expr *set)
 			    string_type) {
 				unsigned int r1len = div_round_up(r1->len, BITS_PER_BYTE);
 				unsigned int str_len = prefix_len / BITS_PER_BYTE;
-				char data[r1len + 1] = {};
+				char data[r1len + 1];
 
+				memset(data, 0, r1len + 1);
 				mpz_export_data(data, r1->value, BYTEORDER_HOST_ENDIAN, r1len);
 				data[str_len] = '*';
 
Signature · 1 line
2.51.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 3 lines · Phil Sutter

Seen with gcc-11.5.0 on an aarch64 machine, build failed. Looking at the code, r1len (or r1->len, actually) really seems variable. So use memset() and fix build for that older compiler version at least.

Thanks for fixing this.

author reviewer
#2 lore raw
Quoted 8 lines · Florian Westphal
Quoted 3 lines · Phil Sutter

Seen with gcc-11.5.0 on an aarch64 machine, build failed. Looking at the code, r1len (or r1->len, actually) really seems variable. So use memset() and fix build for that older compiler version at least.

Thanks for fixing this.

Patch applied, thanks for your review!