From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by passt.top (Postfix, from userid 1000) id 4E1F55A0652; Sun, 03 May 2026 23:56:01 +0200 (CEST) From: Stefano Brivio To: passt-dev@passt.top Subject: [PATCH v6 18/18] fwd_rule: Fix static checkers warnings in fwd_rule_add() Date: Sun, 3 May 2026 23:56:01 +0200 Message-ID: <20260503215601.823029-19-sbrivio@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260503215601.823029-1-sbrivio@redhat.com> References: <20260503215601.823029-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: APSHEXMKLXUSD55RLMPAHNJ37V7NK4KU X-Message-ID-Hash: APSHEXMKLXUSD55RLMPAHNJ37V7NK4KU X-MailFrom: sbrivio@passt.top X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Jon Maloy , David Gibson , Laurent Vivier X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: The new checks are actually sufficient but not enough for Coverity Scan. Now that fwd->sock_count and new->last are affected or supplied by clients, we need explicit (albeit redundant) checks on them. Signed-off-by: Stefano Brivio --- fwd_rule.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fwd_rule.c b/fwd_rule.c index 3c1eaa4..69df99a 100644 --- a/fwd_rule.c +++ b/fwd_rule.c @@ -271,13 +271,22 @@ int fwd_rule_add(struct fwd_table *fwd, const struct fwd_rule *new) warn("Too many rules (maximum %d)", ARRAY_SIZE(fwd->rules)); return -ENOSPC; } + if ((fwd->sock_count + num) > ARRAY_SIZE(fwd->socks)) { warn("Rules require too many listening sockets (maximum %d)", ARRAY_SIZE(fwd->socks)); return -ENOSPC; } + /* Redundant, to make static checkers happy */ + if (fwd->sock_count > ARRAY_SIZE(fwd->socks)) + return -ENOSPC; fwd->rulesocks[fwd->count] = &fwd->socks[fwd->sock_count]; + + /* Redundant ('num' checked above), but not for static checkers */ + if (new->last > ARRAY_SIZE(fwd->socks) + new->first) + return -ENOSPC; + for (port = new->first; port <= new->last; port++) fwd->rulesocks[fwd->count][port - new->first] = -1; -- 2.43.0