diff options
author | Thomas Voss <mail@thomasvoss.com> | 2023-12-30 15:01:52 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2023-12-30 15:01:52 +0100 |
commit | 3ed1a879a9d87a88fc04756f43bc35c04a14ff7b (patch) | |
tree | 354704dbe65225c628d9628f08577549e0b32a2c | |
parent | 835e086804331d4bfa908221e631ff19ad470aef (diff) |
Null-terminate cmdexecb() out buffer
-rw-r--r-- | cbs.h | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -150,7 +150,7 @@ static void cmdclr(cmd_t *c); The cmdexecb() function is like cmdexec() except it writes the given commands standard output to the character buffer pointed to by p. It also stores the - size of the output in *n. + size of the output in *n. The character buffer p is null-terminated. cmdexec() and cmdexecb() have the same return values as cmdwait(). */ static int cmdexec(cmd_t); @@ -422,12 +422,13 @@ cmdexecb(cmd_t c, char **p, size_t *n) die("read"); if (!nr) break; - buf = bufalloc(buf, len + nr, sizeof(char)); + buf = bufalloc(buf, len + nr + 1, sizeof(char)); memcpy(buf + len, tmp, nr); len += nr; } close(fds[FD_R]); + buf[len] = 0; *p = buf; *n = len; return cmdwait(pid); |