Skip to content

Commit c47e940

Browse files
committed
Piped process: fix off-by-one error
The NULL terminator previously was an out-of-bounds write. This fixes the test failure seen in https://github.com/diffblue/cbmc/actions/runs/5112785459/jobs/9191230589?pr=7395, which was locally reproducible. Out-of-bounds write found by `valgrind` via ``` regression/cbmc/dynamic_sizeof1$ valgrind \ ../../../build-coverage/bin/cbmc main.c \ --incremental-smt2-solver 'z3 --smt2 -in' ```
1 parent d5e13f1 commit c47e940

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/util/piped_process.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,10 @@ piped_processt::piped_processt(
277277
dup2(pipe_output[1], STDOUT_FILENO);
278278
dup2(pipe_output[1], STDERR_FILENO);
279279

280-
// Create a char** for the arguments (all the contents of commandvec
281-
// except the first element, i.e. the command itself).
282-
char **args =
283-
reinterpret_cast<char **>(malloc((commandvec.size()) * sizeof(char *)));
280+
// Create a char** for the arguments plus a NULL terminator (by convention,
281+
// the first "argument" is the command itself)
282+
char **args = reinterpret_cast<char **>(
283+
malloc((commandvec.size() + 1) * sizeof(char *)));
284284
// Add all the arguments to the args array of char *.
285285
unsigned long i = 0;
286286
while(i < commandvec.size())

0 commit comments

Comments
 (0)