netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH iproute] bridge: catch invalid stp state
@ 2024-10-07 16:35 Stephen Hemminger
  2024-10-08 16:20 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Stephen Hemminger @ 2024-10-07 16:35 UTC (permalink / raw)
  To: netdev; +Cc: Stephen Hemminger

The stp state parsing was putting result in an __u8 which
would mean that check for invalid string was never happening.

Caught by enabling -Wextra:
    CC       mst.o
mst.c: In function ‘mst_set’:
mst.c:217:27: warning: comparison is always false due to limited range of data type [-Wtype-limits]
  217 |                 if (state == -1) {

Fixes: dae3e5de6eac ("bridge: mst: Add get/set support for MST states")

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>

---
 bridge/mst.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/bridge/mst.c b/bridge/mst.c
index fccb7fd6..32f64aba 100644
--- a/bridge/mst.c
+++ b/bridge/mst.c
@@ -176,7 +176,7 @@ static int mst_set(int argc, char **argv)
 	char *d = NULL, *m = NULL, *s = NULL, *endptr;
 	struct rtattr *af_spec, *mst, *entry;
 	__u16 msti;
-	__u8 state;
+	int state;
 
 	while (argc > 0) {
 		if (strcmp(*argv, "dev") == 0) {
@@ -212,13 +212,12 @@ static int mst_set(int argc, char **argv)
 	}
 
 	state = strtol(s, &endptr, 10);
-	if (!(*s != '\0' && *endptr == '\0')) {
+	if (!(*s != '\0' && *endptr == '\0'))
 		state = parse_stp_state(s);
-		if (state == -1) {
-			fprintf(stderr,
-				"Error: invalid STP port state\n");
-			return -1;
-		}
+	
+	if (state < 0 || state > UINT8_MAX) {
+		fprintf(stderr, "Error: invalid STP port state\n");
+		return -1;
 	}
 
 	af_spec = addattr_nest(&req.n, sizeof(req), IFLA_AF_SPEC);
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH iproute] bridge: catch invalid stp state
  2024-10-07 16:35 [PATCH iproute] bridge: catch invalid stp state Stephen Hemminger
@ 2024-10-08 16:20 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-10-08 16:20 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev

Hello:

This patch was applied to iproute2/iproute2.git (main)
by Stephen Hemminger <stephen@networkplumber.org>:

On Mon,  7 Oct 2024 09:35:43 -0700 you wrote:
> The stp state parsing was putting result in an __u8 which
> would mean that check for invalid string was never happening.
> 
> Caught by enabling -Wextra:
>     CC       mst.o
> mst.c: In function ‘mst_set’:
> mst.c:217:27: warning: comparison is always false due to limited range of data type [-Wtype-limits]
>   217 |                 if (state == -1) {
> 
> [...]

Here is the summary with links:
  - [iproute] bridge: catch invalid stp state
    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=f4b86f752d3c

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-10-08 16:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-07 16:35 [PATCH iproute] bridge: catch invalid stp state Stephen Hemminger
2024-10-08 16:20 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).