From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34150) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YSPRC-00079g-VI for qemu-devel@nongnu.org; Mon, 02 Mar 2015 07:27:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YSPR8-00076g-Vk for qemu-devel@nongnu.org; Mon, 02 Mar 2015 07:27:06 -0500 From: Paolo Bonzini Date: Mon, 2 Mar 2015 13:26:58 +0100 Message-Id: <1425299218-25488-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH] gdbstub: avoid possible NULL pointer dereference List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: qemu-trivial@nongnu.org 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 --- gdbstub.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index e4a1a79..8abcb8a 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 } -- 2.3.0