]> rtime.felk.cvut.cz Git - lisovros/qemu_apohw.git/commitdiff
gdbstub: avoid possible NULL pointer dereference
authorPaolo Bonzini <pbonzini@redhat.com>
Mon, 2 Mar 2015 12:26:58 +0000 (13:26 +0100)
committerMichael Tokarev <mjt@tls.msk.ru>
Tue, 10 Mar 2015 05:15:34 +0000 (08:15 +0300)
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 <pbonzini@redhat.com>
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
gdbstub.c

index e4a1a793843f259b62c50709eace79144ee7c299..8abcb8a45126a8e0b50a05d837eff851db5dab43 100644 (file)
--- 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
 }