All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] dbus-vmstate: replace g_return with error handling
@ 2020-11-18  8:29 marcandre.lureau
  2020-11-18 16:31 ` Markus Armbruster
  0 siblings, 1 reply; 3+ messages in thread
From: marcandre.lureau @ 2020-11-18  8:29 UTC (permalink / raw)
  To: qemu-devel; +Cc: Marc-André Lureau, armbru

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Since g_input_stream_read_all() may return less than requested when the
stream is malformed, we should treat this condition as a runtime user
error (g_return are for programming errors).

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 backends/dbus-vmstate.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/backends/dbus-vmstate.c b/backends/dbus-vmstate.c
index bd050e8e9c..616d291cfb 100644
--- a/backends/dbus-vmstate.c
+++ b/backends/dbus-vmstate.c
@@ -229,7 +229,10 @@ static int dbus_vmstate_post_load(void *opaque, int version_id)
                                      &bytes_read, NULL, &err)) {
             goto error;
         }
-        g_return_val_if_fail(bytes_read == len, -1);
+        if (bytes_read != len) {
+            error_report("%s: Failed to read proxy Id", __func__);
+            return -1;
+        }
         id[len] = 0;
 
         trace_dbus_vmstate_loading(id);
-- 
2.29.0



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

* Re: [PATCH] dbus-vmstate: replace g_return with error handling
  2020-11-18  8:29 [PATCH] dbus-vmstate: replace g_return with error handling marcandre.lureau
@ 2020-11-18 16:31 ` Markus Armbruster
  2021-08-25 15:44   ` Marc-André Lureau
  0 siblings, 1 reply; 3+ messages in thread
From: Markus Armbruster @ 2020-11-18 16:31 UTC (permalink / raw)
  To: marcandre.lureau; +Cc: qemu-devel

marcandre.lureau@redhat.com writes:

> From: Marc-André Lureau <marcandre.lureau@redhat.com>
>
> Since g_input_stream_read_all() may return less than requested when the
> stream is malformed, we should treat this condition as a runtime user
> error (g_return are for programming errors).
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  backends/dbus-vmstate.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/backends/dbus-vmstate.c b/backends/dbus-vmstate.c
> index bd050e8e9c..616d291cfb 100644
> --- a/backends/dbus-vmstate.c
> +++ b/backends/dbus-vmstate.c
> @@ -229,7 +229,10 @@ static int dbus_vmstate_post_load(void *opaque, int version_id)
>                                       &bytes_read, NULL, &err)) {
>              goto error;
>          }
> -        g_return_val_if_fail(bytes_read == len, -1);
> +        if (bytes_read != len) {
> +            error_report("%s: Failed to read proxy Id", __func__);

Error messages containing function names are code smell.  It's
consustent with nearby errors, i.e. this patch is not to blame.

> +            return -1;
> +        }
>          id[len] = 0;
>  
>          trace_dbus_vmstate_loading(id);

Reviewed-by: Markus Armbruster <armbru@redhat.com>



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

* Re: [PATCH] dbus-vmstate: replace g_return with error handling
  2020-11-18 16:31 ` Markus Armbruster
@ 2021-08-25 15:44   ` Marc-André Lureau
  0 siblings, 0 replies; 3+ messages in thread
From: Marc-André Lureau @ 2021-08-25 15:44 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: QEMU

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

Hi

On Wed, Nov 18, 2020 at 8:33 PM Markus Armbruster <armbru@redhat.com> wrote:

> marcandre.lureau@redhat.com writes:
>
> > From: Marc-André Lureau <marcandre.lureau@redhat.com>
> >
> > Since g_input_stream_read_all() may return less than requested when the
> > stream is malformed, we should treat this condition as a runtime user
> > error (g_return are for programming errors).
> >
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >  backends/dbus-vmstate.c | 5 ++++-
> >  1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/backends/dbus-vmstate.c b/backends/dbus-vmstate.c
> > index bd050e8e9c..616d291cfb 100644
> > --- a/backends/dbus-vmstate.c
> > +++ b/backends/dbus-vmstate.c
> > @@ -229,7 +229,10 @@ static int dbus_vmstate_post_load(void *opaque, int
> version_id)
> >                                       &bytes_read, NULL, &err)) {
> >              goto error;
> >          }
> > -        g_return_val_if_fail(bytes_read == len, -1);
> > +        if (bytes_read != len) {
> > +            error_report("%s: Failed to read proxy Id", __func__);
>
> Error messages containing function names are code smell.  It's
> consustent with nearby errors, i.e. this patch is not to blame.
>
> > +            return -1;
> > +        }
> >          id[len] = 0;
> >
> >          trace_dbus_vmstate_loading(id);
>
> Reviewed-by: Markus Armbruster <armbru@redhat.com>
>
>
>
For the record, Markus sent a similar patch later "backends/dbus-vmstate:
Fix short read error handling", which has been applied.

-- 
Marc-André Lureau

[-- Attachment #2: Type: text/html, Size: 2526 bytes --]

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

end of thread, other threads:[~2021-08-25 15:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-18  8:29 [PATCH] dbus-vmstate: replace g_return with error handling marcandre.lureau
2020-11-18 16:31 ` Markus Armbruster
2021-08-25 15:44   ` Marc-André Lureau

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.