do not check pointers after dereferencing them
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
@@ -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
@@ -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
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.csavevm.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
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.cfix is nicer than Stefan's attempt:
https://lists.gnu.org/archive/html/qemu-devel/2013-05/msg04506.htmlReviewed-by Eric Blake <[email protected]>
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
Michael Tokarev
AppliedQuoted 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