aboutgitcodebugslistschat
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2026-05-03 23:56:01 +0200
committerStefano Brivio <sbrivio@redhat.com>2026-05-07 08:06:30 +0200
commite371d347ebb764665f3acd10c804ded44d04bb60 (patch)
tree76882c0a50cf969fbe92530d4fab43bea16d691e
parent4ff9887bfe630aa27178ec38c69e69f7960e1d50 (diff)
downloadpasst-e371d347ebb764665f3acd10c804ded44d04bb60.tar
passt-e371d347ebb764665f3acd10c804ded44d04bb60.tar.gz
passt-e371d347ebb764665f3acd10c804ded44d04bb60.tar.bz2
passt-e371d347ebb764665f3acd10c804ded44d04bb60.tar.lz
passt-e371d347ebb764665f3acd10c804ded44d04bb60.tar.xz
passt-e371d347ebb764665f3acd10c804ded44d04bb60.tar.zst
passt-e371d347ebb764665f3acd10c804ded44d04bb60.zip
fwd_rule: Fix static checkers warnings in fwd_rule_add()
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 <sbrivio@redhat.com> Reviewed-by: Laurent Vivier <lvivier@redhat.com> Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
-rw-r--r--fwd_rule.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/fwd_rule.c b/fwd_rule.c
index b55e4df..200f4b5 100644
--- a/fwd_rule.c
+++ b/fwd_rule.c
@@ -271,13 +271,24 @@ 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 (see check just above), 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, but not for static checkers, that might be missing that
+ * due to the check on 'num' above against ARRAY_SIZE(fwd->socks), we
+ * have a proper upper bound for new->last in the loop below.
+ */
+ 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;