summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2017-07-10 21:36:59 +0200
committerLennart Poettering <lennart@poettering.net>2017-07-10 21:38:36 +0200
commit290843c3852c5d2fda6bef8f3214b23c7d6120ab (patch)
treea60f31ca7761b9c32f3ac91f9cf0e6d1e290f4ee
parent565dab8ef460863ab30126c6be0f3f1af2fa2fb2 (diff)
downloadsystemd-290843c3852c5d2fda6bef8f3214b23c7d6120ab.tar.gz
mount: fix potential bad memory access when /proc/self/mountinfo is empty
It's unlikely this can ever be triggered, but let's be safe rather than sorry, and handle the case where the list of mount points is zero, and the "l" array thus NULL. let's ensure we allocate at least one entry.
-rw-r--r--src/mount/mount-tool.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/mount/mount-tool.c b/src/mount/mount-tool.c
index 0ab06ac3b9..9d56b40700 100644
--- a/src/mount/mount-tool.c
+++ b/src/mount/mount-tool.c
@@ -736,13 +736,13 @@ static int find_mount_points(const char *what, char ***list) {
if (!GREEDY_REALLOC(l, bufsize, n + 2))
return log_oom();
- l[n] = strdup(where);
- if (!l[n])
- return log_oom();
-
- n++;
+ l[n++] = where;
+ where = NULL;
}
+ if (!GREEDY_REALLOC(l, bufsize, n + 1))
+ return log_oom();
+
l[n] = NULL;
*list = l;
l = NULL; /* avoid freeing */