From: Christian Brauner Date: Sun, 10 Sep 2017 04:42:10 +0000 (+0200) Subject: utils: do not write to 0 sized buffer X-Git-Tag: lxc-2.0.9~33 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c04e54bd462e8581ede9aa175e2b88ad15a800a5;p=thirdparty%2Flxc.git utils: do not write to 0 sized buffer Signed-off-by: Christian Brauner --- diff --git a/src/lxc/utils.c b/src/lxc/utils.c index 959481ee2..7cc68d8d2 100644 --- a/src/lxc/utils.c +++ b/src/lxc/utils.c @@ -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 */