From: Daniel Golle Date: Wed, 4 Aug 2021 14:53:07 +0000 (+0100) Subject: hotplug-dispatch: don't ignore asprintf() return value X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=78d5baa015105d4f1da9499a6bbb0364843083b1;p=project%2Fprocd.git hotplug-dispatch: don't ignore asprintf() return value Properly handle asprintf() return value and error out on -1. Signed-off-by: Daniel Golle --- diff --git a/hotplug-dispatch.c b/hotplug-dispatch.c index 6a4fa68..0a285c9 100644 --- a/hotplug-dispatch.c +++ b/hotplug-dispatch.c @@ -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;