]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
bridge: catch invalid stp state
authorStephen Hemminger <stephen@networkplumber.org>
Mon, 7 Oct 2024 16:33:48 +0000 (09:33 -0700)
committerStephen Hemminger <stephen@networkplumber.org>
Mon, 7 Oct 2024 16:33:48 +0000 (09:33 -0700)
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) {

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
bridge/mst.c

index fccb7fd68140b0e4ed5f3b550d99eb083a6252dc..32f64aba98e8f170460e0eb2eccc8d59fbe57986 100644 (file)
@@ -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);