Blame SOURCES/0030-optimize-Clarify-chain_optimize-array-allocations.patch

b59ec1
From 9a41628f4206efe645f5a058a7d71a4503b5869a Mon Sep 17 00:00:00 2001
b59ec1
From: Phil Sutter <psutter@redhat.com>
b59ec1
Date: Tue, 21 Feb 2023 19:50:41 +0100
b59ec1
Subject: [PATCH] optimize: Clarify chain_optimize() array allocations
b59ec1
b59ec1
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2160049
b59ec1
Upstream Status: nftables commit b83a0416cdc88
b59ec1
b59ec1
commit b83a0416cdc881c6ac35739cd858e4fe5fb2e04f
b59ec1
Author: Phil Sutter <phil@nwl.cc>
b59ec1
Date:   Tue Jan 10 22:13:44 2023 +0100
b59ec1
b59ec1
    optimize: Clarify chain_optimize() array allocations
b59ec1
b59ec1
    Arguments passed to sizeof() where deemed suspicious by covscan due to
b59ec1
    the different type. Consistently specify size of an array 'a' using
b59ec1
    'sizeof(*a) * nmemb'.
b59ec1
b59ec1
    For the statement arrays in stmt_matrix, even use xzalloc_array() since
b59ec1
    the item count is fixed and therefore can't be zero.
b59ec1
b59ec1
    Fixes: fb298877ece27 ("src: add ruleset optimization infrastructure")
b59ec1
    Signed-off-by: Phil Sutter <phil@nwl.cc>
b59ec1
b59ec1
Signed-off-by: Phil Sutter <psutter@redhat.com>
b59ec1
---
b59ec1
 src/optimize.c | 7 ++++---
b59ec1
 1 file changed, 4 insertions(+), 3 deletions(-)
b59ec1
b59ec1
diff --git a/src/optimize.c b/src/optimize.c
b59ec1
index 6514cbb..baa6abc 100644
b59ec1
--- a/src/optimize.c
b59ec1
+++ b/src/optimize.c
b59ec1
@@ -918,10 +918,11 @@ static int chain_optimize(struct nft_ctx *nft, struct list_head *rules)
b59ec1
 		ctx->num_rules++;
b59ec1
 	}
b59ec1
 
b59ec1
-	ctx->rule = xzalloc(sizeof(ctx->rule) * ctx->num_rules);
b59ec1
-	ctx->stmt_matrix = xzalloc(sizeof(struct stmt *) * ctx->num_rules);
b59ec1
+	ctx->rule = xzalloc(sizeof(*ctx->rule) * ctx->num_rules);
b59ec1
+	ctx->stmt_matrix = xzalloc(sizeof(*ctx->stmt_matrix) * ctx->num_rules);
b59ec1
 	for (i = 0; i < ctx->num_rules; i++)
b59ec1
-		ctx->stmt_matrix[i] = xzalloc(sizeof(struct stmt *) * MAX_STMTS);
b59ec1
+		ctx->stmt_matrix[i] = xzalloc_array(MAX_STMTS,
b59ec1
+						    sizeof(**ctx->stmt_matrix));
b59ec1
 
b59ec1
 	merge = xzalloc(sizeof(*merge) * ctx->num_rules);
b59ec1
 
b59ec1
-- 
b59ec1
2.39.2
b59ec1