]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
vgdb.c (fork_and_exec_valgrind): Fix off-by-one error write
authorMark Wielaard <mark@klomp.org>
Tue, 12 Nov 2024 12:23:03 +0000 (13:23 +0100)
committerMark Wielaard <mark@klomp.org>
Tue, 12 Nov 2024 12:29:41 +0000 (13:29 +0100)
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.

coregrind/vgdb.c

index d6740aecd460c094e7c0ae95808283b25c9f8f2d..90e3f15020a653a36259be469b92d34e836b37c4 100644 (file)
@@ -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)