]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
utils: do not write to 0 sized buffer
authorChristian Brauner <christian.brauner@ubuntu.com>
Sun, 10 Sep 2017 04:42:10 +0000 (06:42 +0200)
committerStéphane Graber <stgraber@ubuntu.com>
Sun, 24 Sep 2017 04:38:57 +0000 (00:38 -0400)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/utils.c

index 959481ee20fcea582d76cdb3d1835e16cabf476a..7cc68d8d2cead89e57fef020fc559950fe5c7a06 100644 (file)
@@ -2327,9 +2327,11 @@ int run_command(char *buf, size_t buf_size, int (*child_fn)(void *), void *args)
        /* close the write-end of the pipe */
        close(pipefd[1]);
 
-       bytes = read(pipefd[0], buf, (buf_size > 0) ? (buf_size - 1) : 0);
-       if (bytes > 0)
-               buf[bytes - 1] = '\0';
+       if (buf && buf_size > 0) {
+               bytes = read(pipefd[0], buf, buf_size - 1);
+               if (bytes > 0)
+                       buf[bytes - 1] = '\0';
+       }
 
        fret = wait_for_pid(child);
        /* close the read-end of the pipe */