diff mbox series

[iproute2,4/5] ct: check for invalid proto

Message ID 20230628233813.6564-5-stephen@networkplumber.org (mailing list archive)
State Accepted
Commit ac6d95a8465e7d41762fa493ec271ac4584aa0af
Delegated to: David Ahern
Headers show
Series Warning fixes | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Stephen Hemminger June 28, 2023, 11:38 p.m. UTC
Previously since proto was __u8 an invalid proto would
be allowed.  Gcc warns about never true conditional
since __u8 can never be negative.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 tc/m_ct.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Petr Machata June 29, 2023, 1:44 p.m. UTC | #1
Stephen Hemminger <stephen@networkplumber.org> writes:

> Previously since proto was __u8 an invalid proto would
> be allowed.  Gcc warns about never true conditional
> since __u8 can never be negative.
>
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>

Reviewed-by: Petr Machata <me@pmachata.org>
diff mbox series

Patch

diff --git a/tc/m_ct.c b/tc/m_ct.c
index 3e2491b3d192..8c471489778a 100644
--- a/tc/m_ct.c
+++ b/tc/m_ct.c
@@ -161,7 +161,8 @@  static int ct_parse_mark(char *str, struct nlmsghdr *n)
 static int ct_parse_helper(char *str, struct nlmsghdr *n)
 {
 	char f[32], p[32], name[32];
-	__u8 family, proto;
+	__u8 family;
+	int proto;
 
 	if (strlen(str) >= 32 ||
 	    sscanf(str, "%[^-]-%[^-]-%[^-]", f, p, name) != 3)
@@ -172,6 +173,7 @@  static int ct_parse_helper(char *str, struct nlmsghdr *n)
 		family = AF_INET6;
 	else
 		return -1;
+
 	proto = inet_proto_a2n(p);
 	if (proto < 0)
 		return -1;