Skip to contentSkip to conversation

gdbstub: avoid possible NULL pointer dereference

PATCH Applied Paolo Bonzini 2 participants 2 messages Mar 2, 2015 – Mar 4, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 gdbstub.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
gdbstub.c +5 -3
index e4a1a79..8abcb8a 100644
@@ -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
 }
 
Signature · 1 line
2.3.0