qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] do not check pointers after dereferencing them
@ 2013-05-31 12:00 Paolo Bonzini
  2013-05-31 12:46 ` Eric Blake
  2013-05-31 15:39 ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
  0 siblings, 2 replies; 4+ messages in thread
From: Paolo Bonzini @ 2013-05-31 12:00 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-trivial, qemu-stable

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 <pbonzini@redhat.com>
---
 monitor.c |  2 +-
 savevm.c  | 10 +++++-----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/monitor.c b/monitor.c
index 6ce2a4e..eefc7f0 100644
--- a/monitor.c
+++ b/monitor.c
@@ -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 */
diff --git a/savevm.c b/savevm.c
index 31dcce9..4e0fab6 100644
--- a/savevm.c
+++ b/savevm.c
@@ -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;
-- 
1.8.1.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] do not check pointers after dereferencing them
  2013-05-31 12:00 [Qemu-devel] [PATCH] do not check pointers after dereferencing them Paolo Bonzini
@ 2013-05-31 12:46 ` Eric Blake
  2013-06-03  7:58   ` Stefan Hajnoczi
  2013-05-31 15:39 ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
  1 sibling, 1 reply; 4+ messages in thread
From: Eric Blake @ 2013-05-31 12:46 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-trivial, qemu-devel, Stefan Hajnoczi, qemu-stable

[-- Attachment #1: Type: text/plain, Size: 1391 bytes --]

On 05/31/2013 06:00 AM, Paolo Bonzini wrote:
> 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 <pbonzini@redhat.com>
> ---
>  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

Reviewed-by: Eric Blake <eblake@redhat.com>

> +++ b/savevm.c
> @@ -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;
> 

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 621 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [Qemu-trivial] [PATCH] do not check pointers after dereferencing them
  2013-05-31 12:00 [Qemu-devel] [PATCH] do not check pointers after dereferencing them Paolo Bonzini
  2013-05-31 12:46 ` Eric Blake
@ 2013-05-31 15:39 ` Michael Tokarev
  1 sibling, 0 replies; 4+ messages in thread
From: Michael Tokarev @ 2013-05-31 15:39 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-trivial, qemu-devel, qemu-stable

31.05.2013 16:00, Paolo Bonzini wrote:
> 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] do not check pointers after dereferencing them
  2013-05-31 12:46 ` Eric Blake
@ 2013-06-03  7:58   ` Stefan Hajnoczi
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Hajnoczi @ 2013-06-03  7:58 UTC (permalink / raw)
  To: Eric Blake; +Cc: qemu-trivial, Paolo Bonzini, qemu-devel, qemu-stable

On Fri, May 31, 2013 at 06:46:21AM -0600, Eric Blake wrote:
> On 05/31/2013 06:00 AM, Paolo Bonzini wrote:
> > 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 <pbonzini@redhat.com>
> > ---
> >  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
> 
> Reviewed-by: Eric Blake <eblake@redhat.com>

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-06-03  7:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-31 12:00 [Qemu-devel] [PATCH] do not check pointers after dereferencing them Paolo Bonzini
2013-05-31 12:46 ` Eric Blake
2013-06-03  7:58   ` Stefan Hajnoczi
2013-05-31 15:39 ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).