From: Mark W. <ma...@so...> - 2024-11-26 21:14:50
|
https://sourceware.org/git/gitweb.cgi?p=valgrind.git;h=2cb0bee2d7722b57956f66a0795b5b9106f88afc commit 2cb0bee2d7722b57956f66a0795b5b9106f88afc Author: Mark Wielaard <ma...@kl...> Date: Tue Nov 12 13:23:03 2024 +0100 vgdb.c (fork_and_exec_valgrind): Fix off-by-one error write commit 646978d9adc5 ("vgdb: Handle EINTR and EAGAIN more consistently") introduced an off-by-one issue trying to write back the error from child to parent. Instead of +1 it should have been +written (which initially is zero). This is in an "should never happen" path, so hopefully didn't really cause issues. But if it did happen the parent would have gotten the wrong error code. (cherry picked from commit f4fe5faf3d0f45b3824bbb9070232682df52a582) Diff: --- coregrind/vgdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coregrind/vgdb.c b/coregrind/vgdb.c index 786ead160d..112f23fe6b 100644 --- a/coregrind/vgdb.c +++ b/coregrind/vgdb.c @@ -1368,7 +1368,7 @@ int fork_and_exec_valgrind (int argc, char **argv, const char *working_dir, // We try to write the result to the parent, but always exit. size_t written = 0; while (written < sizeof (int)) { - ssize_t nrw = write (pipefd[1], ((char *) &err) + 1, + ssize_t nrw = write (pipefd[1], ((char *) &err) + written, sizeof (int) - written); if (nrw == -1) { if (errno == EINTR || errno == EAGAIN) |