From 3d0f44189178aab3a21a33ecf6a113b9abaea2bc Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Mon, 2 Mar 2015 13:26:58 +0100 Subject: gdbstub: avoid possible NULL pointer dereference Coverity reports that s->chr is checked after put_packet dereferences it. Move the check earlier, consistent with the code used for user-mode emulation. Signed-off-by: Paolo Bonzini Signed-off-by: Michael Tokarev --- gdbstub.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'gdbstub.c') diff --git a/gdbstub.c b/gdbstub.c index e4a1a79384..8abcb8a451 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -1443,15 +1443,17 @@ void gdb_exit(CPUArchState *env, int code) if (gdbserver_fd < 0 || s->fd < 0) { return; } +#else + if (!s->chr) { + return; + } #endif snprintf(buf, sizeof(buf), "W%02x", (uint8_t)code); put_packet(s, buf); #ifndef CONFIG_USER_ONLY - if (s->chr) { - qemu_chr_delete(s->chr); - } + qemu_chr_delete(s->chr); #endif } -- cgit v1.2.3