Skip to contentSkip to conversation

do not check pointers after dereferencing them

PATCH Applied Paolo Bonzini 4 participants 4 messages May 31, 2013 – Jun 3, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 do not check pointers after dereferencing them

Two instances, both spotted by Coverity. In one, two blocks were swapped. In the other, the check is not needed anymore.

---
 monitor.c |  2 +-
 savevm.c  | 10 +++++-----
 2 files changed, 6 insertions(+), 6 deletions(-)
monitor.c +1 -1
index 6ce2a4e..eefc7f0 100644
@@ -280,7 +280,7 @@ void monitor_flush(Monitor *mon)
     buf = qstring_get_str(mon->outbuf);
     len = qstring_get_length(mon->outbuf);
 
-    if (mon && len && !mon->mux_out) {
+    if (len && !mon->mux_out) {
         rc = qemu_chr_fe_write(mon->chr, (const uint8_t *) buf, len);
         if (rc == len) {
             /* all flushed */
savevm.c +5 -5
index 31dcce9..4e0fab6 100644
@@ -322,16 +322,16 @@ QEMUFile *qemu_popen_cmd(const char *command, const char *mode)
     FILE *stdio_file;
     QEMUFileStdio *s;
 
-    stdio_file = popen(command, mode);
-    if (stdio_file == NULL) {
-        return NULL;
-    }
-
     if (mode == NULL || (mode[0] != 'r' && mode[0] != 'w') || mode[1] != 0) {
         fprintf(stderr, "qemu_popen: Argument validity check failed\n");
         return NULL;
     }
 
+    stdio_file = popen(command, mode);
+    if (stdio_file == NULL) {
+        return NULL;
+    }
+
     s = g_malloc0(sizeof(QEMUFileStdio));
 
     s->stdio_file = stdio_file;
Signature · 1 line
1.8.1.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Paolo Bonzini

Two instances, both spotted by Coverity. In one, two blocks were swapped. In the other, the check is not needed anymore.

---
 monitor.c |  2 +-
 savevm.c  | 10 +++++-----
 2 files changed, 6 insertions(+), 6 deletions(-)

This version of the savevm.c fix is nicer than Stefan's attempt:
https://lists.gnu.org/archive/html/qemu-devel/2013-05/msg04506.html

Quoted 24 lines

+++ b/savevm.c

savevm.c +5 -5
@@ -322,16 +322,16 @@ QEMUFile *qemu_popen_cmd(const char *command, const char *mode)
     FILE *stdio_file;
     QEMUFileStdio *s;
 
-    stdio_file = popen(command, mode);
-    if (stdio_file == NULL) {
-        return NULL;
-    }
-
     if (mode == NULL || (mode[0] != 'r' && mode[0] != 'w') || mode[1] != 0) {
         fprintf(stderr, "qemu_popen: Argument validity check failed\n");
         return NULL;
     }
 
+    stdio_file = popen(command, mode);
+    if (stdio_file == NULL) {
+        return NULL;
+    }
+
     s = g_malloc0(sizeof(QEMUFileStdio));
 
     s->stdio_file = stdio_file;
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#2 lore raw
Quoted 12 lines · Eric Blake
Quoted 10 lines · Paolo Bonzini

Two instances, both spotted by Coverity. In one, two blocks were swapped. In the other, the check is not needed anymore.

---
 monitor.c |  2 +-
 savevm.c  | 10 +++++-----
 2 files changed, 6 insertions(+), 6 deletions(-)
Quoted 4 lines

This version of the savevm.c fix is nicer than Stefan's attempt:
https://lists.gnu.org/archive/html/qemu-devel/2013-05/msg04506.html

I'll drop mine. I didn't dare to swap the blocks just in case something dependend on doing the popen() and bailing out afterwards, but it's hard to imagine that.

Stefan

#3 lore raw
In reply to Paolo Bonzini
Quoted 2 lines · Paolo Bonzini

Two instances, both spotted by Coverity. In one, two blocks were swapped. In the other, the check is not needed anymore.

Thanks, applied to the trivial patches queue.

/mjt