Skip to content

Commit

Permalink
gdbstub: Fix double close() of the follow-fork-mode socket
Browse files Browse the repository at this point in the history
When the terminal GDB_FORK_ENABLED state is reached, the coordination
socket is not needed anymore and is therefore closed. However, if there
is a communication error between QEMU gdbstub and GDB, the generic
error handling code attempts to close it again.

Fix by closing it later - before returning - instead.

Fixes: Coverity CID 1539966
Fixes: d547e71 ("gdbstub: Implement follow-fork-mode child")
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20240312001813.13720-1-iii@linux.ibm.com>
  • Loading branch information
iii-i authored and stsquad committed Mar 12, 2024
1 parent 0d57c04 commit 0532045
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions gdbstub/user.c
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ void gdbserver_fork_end(CPUState *cpu, pid_t pid)
switch (gdbserver_user_state.fork_state) {
case GDB_FORK_ENABLED:
if (gdbserver_user_state.running_state) {
close(fd);
return;
}
QEMU_FALLTHROUGH;
Expand All @@ -542,7 +543,6 @@ void gdbserver_fork_end(CPUState *cpu, pid_t pid)
gdbserver_user_state.fork_state = GDB_FORK_ACTIVE;
break;
case GDB_FORK_ENABLE:
close(fd);
gdbserver_user_state.fork_state = GDB_FORK_ENABLED;
break;
case GDB_FORK_DISABLE:
Expand All @@ -557,7 +557,6 @@ void gdbserver_fork_end(CPUState *cpu, pid_t pid)
if (write(fd, &b, 1) != 1) {
goto fail;
}
close(fd);
gdbserver_user_state.fork_state = GDB_FORK_ENABLED;
break;
case GDB_FORK_DISABLING:
Expand Down

0 comments on commit 0532045

Please sign in to comment.