Skip to contentSkip to conversation

dbus-vmstate: replace g_return with error handling

PATCH In review [email protected] 3 participants 3 messages Nov 18, 2020 – Aug 25, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dbus-vmstate: replace g_return with error handling

From: Marc-André Lureau <[email protected]>

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).

---
 backends/dbus-vmstate.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
backends/dbus-vmstate.c +4 -1
index bd050e8e9c..616d291cfb 100644
@@ -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);
Signature · 1 line
2.29.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines · [email protected] writes:

From: Marc-André Lureau <[email protected]>

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).

---
 backends/dbus-vmstate.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
backends/dbus-vmstate.c +0 -0
index bd050e8e9c..616d291cfb 100644

backends/dbus-vmstate.c static int dbus_vmstate_post_load(void *opaque, int version_id) · line 233

Quoted 6 lines
backends/dbus-vmstate.c +2 -1
@@ -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.

backends/dbus-vmstate.c static int dbus_vmstate_post_load(void *opaque, int version_id) · line 238

Quoted 5 lines
backends/dbus-vmstate.c +2 -0
+            return -1;
+        }
         id[len] = 0;
 
         trace_dbus_vmstate_loading(id);
#2 lore raw

Hi

Quoted 29 lines · Markus Armbruster

backends/dbus-vmstate.c static int dbus_vmstate_post_load(void *opaque, int

Quoted 16 lines · [email protected] writes:

From: Marc-André Lureau <[email protected]>

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).

---
 backends/dbus-vmstate.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
backends/dbus-vmstate.c +0 -0
index bd050e8e9c..616d291cfb 100644
@@ -229,7 +229,10 @@ static int dbus_vmstate_post_load(void *opaque, int

version_id)

backends/dbus-vmstate.c static int dbus_vmstate_post_load(void *opaque, int version_id) · line 233

Quoted 6 lines
backends/dbus-vmstate.c +2 -1
                                      &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.

Quoted 10 lines

backends/dbus-vmstate.c static int dbus_vmstate_post_load(void *opaque, int version_id) · line 238

Quoted 5 lines
backends/dbus-vmstate.c +2 -0
+            return -1;
+        }
         id[len] = 0;
 
         trace_dbus_vmstate_loading(id);

For the record, Markus sent a similar patch later "backends/dbus-vmstate:
Fix short read error handling", which has been applied.

Signature · 1 line
Marc-André Lureau