]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
devlink: Check return code of strslashrsplit()
authorPhil Sutter <phil@nwl.cc>
Mon, 21 Aug 2017 16:36:52 +0000 (18:36 +0200)
committerStephen Hemminger <stephen@networkplumber.org>
Tue, 22 Aug 2017 00:28:03 +0000 (17:28 -0700)
This function shouldn't fail because all callers of
__dl_argv_handle_port() make sure the passed string contains enough
slashes already, but better make sure if this changes in future the
function won't access uninitialized data.

Signed-off-by: Phil Sutter <phil@nwl.cc>
devlink/devlink.c

index 5b325ce6c657c428f9ac4040ed777e3b607b3c6c..8f11f865bfc4043802fcaf254c10924f74ce2406 100644 (file)
@@ -526,18 +526,26 @@ static int __dl_argv_handle_port(char *str,
                                 char **p_bus_name, char **p_dev_name,
                                 uint32_t *p_port_index)
 {
-       char *handlestr = handlestr;
-       char *portstr = portstr;
+       char *handlestr;
+       char *portstr;
        int err;
 
-       strslashrsplit(str, &handlestr, &portstr);
+       err = strslashrsplit(str, &handlestr, &portstr);
+       if (err) {
+               pr_err("Port identification \"%s\" is invalid\n", str);
+               return err;
+       }
        err = strtouint32_t(portstr, p_port_index);
        if (err) {
                pr_err("Port index \"%s\" is not a number or not within range\n",
                       portstr);
                return err;
        }
-       strslashrsplit(handlestr, p_bus_name, p_dev_name);
+       err = strslashrsplit(handlestr, p_bus_name, p_dev_name);
+       if (err) {
+               pr_err("Port identification \"%s\" is invalid\n", str);
+               return err;
+       }
        return 0;
 }