mount: fix potential bad memory access when /proc/self/mountinfo is empty
authorLennart Poettering <lennart@poettering.net>
Mon, 10 Jul 2017 19:36:59 +0000 (21:36 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 10 Jul 2017 19:38:36 +0000 (21:38 +0200)
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.

src/mount/mount-tool.c

index 0ab06ac..9d56b40 100644 (file)
@@ -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 */