Skip to contentSkip to conversation

hw/xen: Fix trace_xs_node_read() params

PATCH In review Liam Merwick 5 participants 5 messages May 23, 2025 – May 27, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/xen: Fix trace_xs_node_read() params

When the '--enable-trace-backends=syslog' build option is configured, the following compilation error is encountered.

In file included from /usr/include/sys/syslog.h:207,

                 from /usr/include/syslog.h:1,
                 from ./trace/trace-hw_xen.h:224,
                 from ../hw/xen/trace.h:1,
                 from ../hw/xen/xen-bus-helper.c:13:

In function ‘syslog’,
inlined from ‘_nocheck__trace_xs_node_read’ at ../hw/xen/trace-events:41:9, inlined from ‘trace_xs_node_read’ at trace/trace-hw_xen.h:903:9,
inlined from ‘xs_node_read’ at ../hw/xen/xen-bus-helper.c:154:5:
/usr/include/bits/syslog.h:45:3: error: ‘%s’ directive argument is null [-Werror=format-overflow=]

   45 |   __syslog_chk (__pri, __USE_FORTIFY_LEVEL - 1, __fmt, __va_arg_pack ());
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Add a check that 'value' is not null before passing it to trace_xs_node_read().

Fixes e6cdeee95990 ("hw/xen: Add xs_node_read() helper function")
---
 hw/xen/xen-bus-helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/xen/xen-bus-helper.c +1 -1
index 288fad422be3..1087a585cc71 100644
@@ -151,7 +151,7 @@ char *xs_node_read(struct qemu_xs_handle *h, xs_transaction_t tid,
     va_end(ap);
 
     value = qemu_xen_xs_read(h, tid, path, len);
-    trace_xs_node_read(path, value);
+    trace_xs_node_read(path, value ? value : "<null>");
     if (!value) {
         error_setg_errno(errp, errno, "failed to read from '%s'", path);
     }
Signature · 1 line
2.47.1
Acked-by on v1 1/1
#1 lore raw
Quoted 16 lines · Liam Merwick

When the '--enable-trace-backends=syslog' build option is configured, the following compilation error is encountered.

In file included from /usr/include/sys/syslog.h:207,
                 from /usr/include/syslog.h:1,
                 from ./trace/trace-hw_xen.h:224,
                 from ../hw/xen/trace.h:1,
                 from ../hw/xen/xen-bus-helper.c:13:
In function ‘syslog’,
    inlined from ‘_nocheck__trace_xs_node_read’ at ../hw/xen/trace-events:41:9, inlined from ‘trace_xs_node_read’ at trace/trace-hw_xen.h:903:9,
    inlined from ‘xs_node_read’ at ../hw/xen/xen-bus-helper.c:154:5:
/usr/include/bits/syslog.h:45:3: error: ‘%s’ directive argument is null [-Werror=format-overflow=] 45 |   __syslog_chk (__pri, __USE_FORTIFY_LEVEL - 1, __fmt, __va_arg_pack ()); |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Quoted 4 lines

Add a check that 'value' is not null before passing it to trace_xs_node_read().

Fixes e6cdeee95990 ("hw/xen: Add xs_node_read() helper function")

Thanks.

Acked-by on v1 1/1
#2 lore raw
In reply to Liam Merwick
Quoted 13 lines · Liam Merwick

When the '--enable-trace-backends=syslog' build option is configured, the following compilation error is encountered.

In file included from /usr/include/sys/syslog.h:207,

                 from /usr/include/syslog.h:1,
                 from ./trace/trace-hw_xen.h:224,
                 from ../hw/xen/trace.h:1,
                 from ../hw/xen/xen-bus-helper.c:13:

In function ‘syslog’,
inlined from ‘_nocheck__trace_xs_node_read’ at ../hw/xen/trace-events:41:9, inlined from ‘trace_xs_node_read’ at trace/trace-hw_xen.h:903:9,
inlined from ‘xs_node_read’ at ../hw/xen/xen-bus-helper.c:154:5:
/usr/include/bits/syslog.h:45:3: error: ‘%s’ directive argument is null [-Werror=format-overflow=]

Quoted 7 lines
   45 |   __syslog_chk (__pri, __USE_FORTIFY_LEVEL - 1, __fmt, __va_arg_pack ());
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Add a check that 'value' is not null before passing it to trace_xs_node_read().

Fixes e6cdeee95990 ("hw/xen: Add xs_node_read() helper function")

Thanks,

Signature · 1 line
Anthony PERARD
Reviewed-by on v1 1/1
#3 lore raw
In reply to Liam Merwick
Quoted 29 lines · Liam Merwick

When the '--enable-trace-backends=syslog' build option is configured, the following compilation error is encountered.

In file included from /usr/include/sys/syslog.h:207,

                  from /usr/include/syslog.h:1,
                  from ./trace/trace-hw_xen.h:224,
                  from ../hw/xen/trace.h:1,
                  from ../hw/xen/xen-bus-helper.c:13:

In function ‘syslog’,
inlined from ‘_nocheck__trace_xs_node_read’ at ../hw/xen/trace-events:41:9, inlined from ‘trace_xs_node_read’ at trace/trace-hw_xen.h:903:9,
inlined from ‘xs_node_read’ at ../hw/xen/xen-bus-helper.c:154:5:
/usr/include/bits/syslog.h:45:3: error: ‘%s’ directive argument is null [-Werror=format-overflow=]

    45 |   __syslog_chk (__pri, __USE_FORTIFY_LEVEL - 1, __fmt, __va_arg_pack ());
       |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Add a check that 'value' is not null before passing it to trace_xs_node_read().

Fixes e6cdeee95990 ("hw/xen: Add xs_node_read() helper function")
---
  hw/xen/xen-bus-helper.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/xen/xen-bus-helper.c +0 -0
index 288fad422be3..1087a585cc71 100644

hw/xen/xen-bus-helper.c char *xs_node_read(struct qemu_xs_handle *h, xs_transaction_t tid, · line 157

Quoted 8 lines
hw/xen/xen-bus-helper.c +1 -1
@@ -151,7 +151,7 @@ char *xs_node_read(struct qemu_xs_handle *h, xs_transaction_t tid,
      va_end(ap);
 
      value = qemu_xen_xs_read(h, tid, path, len);
-    trace_xs_node_read(path, value);
+    trace_xs_node_read(path, value ? value : "<null>");
      if (!value) {
          error_setg_errno(errp, errno, "failed to read from '%s'", path);
      }

Alternatively, since this is an error path:

-- >8 --

hw/xen/xen-bus-helper.c +4 -4
index 288fad422be..1e49e60e147 100644
@@ -143,7 +143,8 @@ char *xs_node_read(struct qemu_xs_handle *h, xs_transaction_t tid,
                    unsigned int *len, Error **errp,
                    const char *path_fmt, ...)
 {
-    char *path, *value;
+    g_autofree char *value;
+    char *path;
     va_list ap;
 
     va_start(ap, path_fmt);
@@ -151,12 +152,11 @@ char *xs_node_read(struct qemu_xs_handle *h, xs_transaction_t tid,
     va_end(ap);
 
     value = qemu_xen_xs_read(h, tid, path, len);
-    trace_xs_node_read(path, value);
     if (!value) {
         error_setg_errno(errp, errno, "failed to read from '%s'", path);
+        return NULL;
     }
-
-    g_free(path);
+    trace_xs_node_read(path, value);
 
     return value;
 }

---

But your patch isn't wrong, so:

#4 lore raw
Quoted 18 lines · Philippe Mathieu-Daudé

Alternatively, since this is an error path:

-- >8 --

hw/xen/xen-bus-helper.c +2 -1
index 288fad422be..1e49e60e147 100644
@@ -143,7 +143,8 @@ char *xs_node_read(struct qemu_xs_handle *h, xs_transaction_t tid,
                     unsigned int *len, Error **errp,
                     const char *path_fmt, ...)
  {
-    char *path, *value;
+    g_autofree char *value;
+    char *path;
      va_list ap;
 
      va_start(ap, path_fmt);

hw/xen/xen-bus-helper.c char *xs_node_read(struct qemu_xs_handle *h, xs_transaction_t tid, · line 158

Quoted 8 lines
hw/xen/xen-bus-helper.c +1 -1
@@ -151,12 +152,11 @@ char *xs_node_read(struct qemu_xs_handle *h, xs_transaction_t tid,
      va_end(ap);
 
      value = qemu_xen_xs_read(h, tid, path, len);
-    trace_xs_node_read(path, value);
      if (!value) {
          error_setg_errno(errp, errno, "failed to read from '%s'", path);
+        return NULL;
      }

Auto-free variables must be initialized.

r~