summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKieran Bingham <kieran.bingham@ideasonboard.com>2018-06-27 00:07:54 +0100
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2018-07-31 15:56:38 +0300
commit29994a50817d67c289277ef296215cbbffb7c19d (patch)
treeb3518e850617dee3475871bc0976c20c9fcde4b1
parent3ec5aa6720c32d32cd26cf52c0e35bf61830c879 (diff)
lib: configfs: Fix asprintf return value usage
The asprintf function returns -1, and leaves the first parameter undefined in case of an allocation error. This conflicts with the code's assumption that the parameter is set NULL on error. Check all return values of asprintf, and ensure that the string parameter is not used as a return value on error paths. Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
-rw-r--r--lib/configfs.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/lib/configfs.c b/lib/configfs.c
index 1dfde95..5de7079 100644
--- a/lib/configfs.c
+++ b/lib/configfs.c
@@ -32,8 +32,17 @@
static char *path_join(const char *dirname, const char *name)
{
char *path;
+ int ret;
+
+ ret = asprintf(&path, "%s/%s", dirname, name);
- asprintf(&path, "%s/%s", dirname, name);
+ /*
+ * asprintf returns -1 on allocation or other errors, leaving 'path'
+ * undefined. We shouldn't even call free(path) here. We want to return
+ * NULL on error, so we must manually set it.
+ */
+ if (ret < 0)
+ path = NULL;
return path;
}
@@ -192,10 +201,12 @@ static char *udc_find_video_device(const char *udc, const char *function)
char *video = NULL;
glob_t globbuf;
unsigned int i;
+ int ret;
- asprintf(&vpath, "/sys/class/udc/%s/device/gadget/video4linux/video*",
- udc ? udc : "*");
- if (!vpath)
+ ret = asprintf(&vpath,
+ "/sys/class/udc/%s/device/gadget/video4linux/video*",
+ udc ? udc : "*");
+ if (!ret)
return NULL;
glob(vpath, 0, NULL, &globbuf);