From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40193) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UmsrV-0006ha-Cr for qemu-devel@nongnu.org; Wed, 12 Jun 2013 17:45:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UmsrU-0001BS-0N for qemu-devel@nongnu.org; Wed, 12 Jun 2013 17:45:49 -0400 Sender: fluxion From: Michael Roth Date: Wed, 12 Jun 2013 16:41:27 -0500 Message-Id: <1371073298-14519-16-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1371073298-14519-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1371073298-14519-1-git-send-email-mdroth@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 15/26] do not check pointers after dereferencing them List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org From: Paolo Bonzini Two instances, both spotted by Coverity. In one, two blocks were swapped. In the other, the check is not needed anymore. Cc: qemu-stable@nongnu.org Cc: qemu-trivial@nongnu.org Signed-off-by: Paolo Bonzini Reviewed-by: Eric Blake Signed-off-by: Michael Tokarev (cherry picked from commit a4cc73d629d43c8a4d171d043ff229a959df3ca6) Signed-off-by: Michael Roth --- monitor.c | 2 +- savevm.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/monitor.c b/monitor.c index 62aaebe..dee980c 100644 --- a/monitor.c +++ b/monitor.c @@ -281,7 +281,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 */ diff --git a/savevm.c b/savevm.c index 31dcce9..4e0fab6 100644 --- a/savevm.c +++ b/savevm.c @@ -322,13 +322,13 @@ QEMUFile *qemu_popen_cmd(const char *command, const char *mode) FILE *stdio_file; QEMUFileStdio *s; - stdio_file = popen(command, mode); - if (stdio_file == NULL) { + if (mode == NULL || (mode[0] != 'r' && mode[0] != 'w') || mode[1] != 0) { + fprintf(stderr, "qemu_popen: Argument validity check failed\n"); return NULL; } - if (mode == NULL || (mode[0] != 'r' && mode[0] != 'w') || mode[1] != 0) { - fprintf(stderr, "qemu_popen: Argument validity check failed\n"); + stdio_file = popen(command, mode); + if (stdio_file == NULL) { return NULL; } -- 1.7.9.5