]> 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)
committerChristian Brauner <christian.brauner@ubuntu.com>
Sun, 10 Sep 2017 21:49:31 +0000 (23:49 +0200)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/utils.c

index 07257d29a0f4ae806bbc2c7050e2b30978ff546c..656d3ca843e5425dfab6247ad36ed5d65eaf71ff 100644 (file)
@@ -2330,9 +2330,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 */