summaryrefslogtreecommitdiff
path: root/gdbstub.c
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2015-03-02 13:26:58 +0100
committerMichael Tokarev <mjt@tls.msk.ru>2015-03-10 08:15:34 +0300
commit3d0f44189178aab3a21a33ecf6a113b9abaea2bc (patch)
tree467b8b699bbe644ac4e60a624ed3d905ca272444 /gdbstub.c
parentc6dc3dd72b747a057770087998a1f9ef0b3f1882 (diff)
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 <pbonzini@redhat.com> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Diffstat (limited to 'gdbstub.c')
-rw-r--r--gdbstub.c8
1 files changed, 5 insertions, 3 deletions
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
}