hotplug-dispatch: don't ignore asprintf() return value
authorDaniel Golle <daniel@makrotopia.org>
Wed, 4 Aug 2021 14:53:07 +0000 (15:53 +0100)
committerDaniel Golle <daniel@makrotopia.org>
Wed, 4 Aug 2021 14:53:07 +0000 (15:53 +0100)
Properly handle asprintf() return value and error out on -1.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
hotplug-dispatch.c

index 6a4fa68a00a56b1a9657f445bcb4d172bb7e1de6..0a285c9727ebf6f9fd9f4ba92150a357644d7fc3 100644 (file)
@@ -105,7 +105,11 @@ static void hotplug_exec(struct uloop_timeout *t)
                return;
        }
 
-       asprintf(&script, ". /lib/functions.sh\n. %s\n", pc->globbuf.gl_pathv[pc->cnt++]);
+       if (asprintf(&script, ". /lib/functions.sh\n. %s\n", pc->globbuf.gl_pathv[pc->cnt++]) == -1) {
+               pc->ret = ENOMEM;
+               return;
+       }
+
        /* prepare for execve() */
        exec_argv[0] = "/bin/sh";
        exec_argv[1] = "-c";
@@ -302,7 +306,8 @@ static void add_subsystem(int nlen, char *newname)
        struct hotplug_subsys *nh = calloc(1, sizeof(struct hotplug_subsys));
        char *name;
 
-       asprintf(&name, "%s%.*s", HOTPLUG_OBJECT_PREFIX, nlen, newname);
+       if (asprintf(&name, "%s%.*s", HOTPLUG_OBJECT_PREFIX, nlen, newname) == -1)
+               exit(ENOMEM);
 
        /* prepare and add ubus object */
        nh->ubus.name = name;