uxc: fix potential NULL-pointer dereference
authorDaniel Golle <daniel@makrotopia.org>
Sun, 20 Feb 2022 12:43:36 +0000 (12:43 +0000)
committerDaniel Golle <daniel@makrotopia.org>
Wed, 13 Apr 2022 02:58:39 +0000 (03:58 +0100)
Check for NULL returned by strrchr() and return error in that case.
It should not be reachable as the string should always contain a '/'
character, but follow best practices anyway.

Coverity CID: 1500356 Dereference null return value
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
uxc.c

diff --git a/uxc.c b/uxc.c
index 332b91d268e56bd9cd383f9c9f995a8c7c1c4c0d..c15b4bc42cbeb93b0262edc741b4d025fcf1a197 100644 (file)
--- a/uxc.c
+++ b/uxc.c
@@ -1032,6 +1032,9 @@ static int uxc_set(char *name, char *path, signed char autostart, char *pidfile,
                        char *t1, *t2;
                        t1 = strdup(cfname);
                        t2 = strrchr(t1, '/');
+                       if (!t2)
+                               return -EINVAL;
+
                        *t2 = '\0';
 
                        if (asprintf(&t2, "%s/settings", t1) == -1)