qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hw/xen: Fix trace_xs_node_read() params
@ 2025-05-23 16:01 Liam Merwick
  2025-05-23 16:46 ` [EXTERNAL] " David Woodhouse
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Liam Merwick @ 2025-05-23 16:01 UTC (permalink / raw)
  To: dwmw, anthony.perard, roger.pau, xen-devel, qemu-devel,
	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")
Signed-off-by: Liam Merwick <liam.merwick@oracle.com>
---
 hw/xen/xen-bus-helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/xen/xen-bus-helper.c b/hw/xen/xen-bus-helper.c
index 288fad422be3..1087a585cc71 100644
--- a/hw/xen/xen-bus-helper.c
+++ b/hw/xen/xen-bus-helper.c
@@ -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);
     }
-- 
2.47.1



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

* Re: [EXTERNAL] [PATCH] hw/xen: Fix trace_xs_node_read() params
  2025-05-23 16:01 [PATCH] hw/xen: Fix trace_xs_node_read() params Liam Merwick
@ 2025-05-23 16:46 ` David Woodhouse
  2025-05-26 16:19 ` Anthony PERARD
  2025-05-26 18:10 ` Philippe Mathieu-Daudé
  2 siblings, 0 replies; 5+ messages in thread
From: David Woodhouse @ 2025-05-23 16:46 UTC (permalink / raw)
  To: Liam Merwick, anthony.perard, roger.pau, xen-devel, qemu-devel

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

On Fri, 2025-05-23 at 16:01 +0000, Liam Merwick wrote:
> 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")
> Signed-off-by: Liam Merwick <liam.merwick@oracle.com>

Acked-by: David Woodhouse <dwmw@amazon.co.uk>

Thanks.

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5069 bytes --]

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

* Re: [PATCH] hw/xen: Fix trace_xs_node_read() params
  2025-05-23 16:01 [PATCH] hw/xen: Fix trace_xs_node_read() params Liam Merwick
  2025-05-23 16:46 ` [EXTERNAL] " David Woodhouse
@ 2025-05-26 16:19 ` Anthony PERARD
  2025-05-26 18:10 ` Philippe Mathieu-Daudé
  2 siblings, 0 replies; 5+ messages in thread
From: Anthony PERARD @ 2025-05-26 16:19 UTC (permalink / raw)
  To: Liam Merwick; +Cc: dwmw, roger.pau, xen-devel, qemu-devel

On Fri, May 23, 2025 at 04:01:34PM +0000, Liam Merwick wrote:
> 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")
> Signed-off-by: Liam Merwick <liam.merwick@oracle.com>

Acked-by: Anthony PERARD <anthony.perard@vates.tech>

Thanks,

-- 
Anthony PERARD


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

* Re: [PATCH] hw/xen: Fix trace_xs_node_read() params
  2025-05-23 16:01 [PATCH] hw/xen: Fix trace_xs_node_read() params Liam Merwick
  2025-05-23 16:46 ` [EXTERNAL] " David Woodhouse
  2025-05-26 16:19 ` Anthony PERARD
@ 2025-05-26 18:10 ` Philippe Mathieu-Daudé
  2025-05-27  7:22   ` Richard Henderson
  2 siblings, 1 reply; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-05-26 18:10 UTC (permalink / raw)
  To: Liam Merwick, dwmw, anthony.perard, roger.pau, xen-devel,
	qemu-devel

On 23/5/25 18:01, Liam Merwick wrote:
> 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")
> Signed-off-by: Liam Merwick <liam.merwick@oracle.com>
> ---
>   hw/xen/xen-bus-helper.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/xen/xen-bus-helper.c b/hw/xen/xen-bus-helper.c
> index 288fad422be3..1087a585cc71 100644
> --- a/hw/xen/xen-bus-helper.c
> +++ b/hw/xen/xen-bus-helper.c
> @@ -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 --
diff --git a/hw/xen/xen-bus-helper.c b/hw/xen/xen-bus-helper.c
index 288fad422be..1e49e60e147 100644
--- a/hw/xen/xen-bus-helper.c
+++ b/hw/xen/xen-bus-helper.c
@@ -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:
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>



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

* Re: [PATCH] hw/xen: Fix trace_xs_node_read() params
  2025-05-26 18:10 ` Philippe Mathieu-Daudé
@ 2025-05-27  7:22   ` Richard Henderson
  0 siblings, 0 replies; 5+ messages in thread
From: Richard Henderson @ 2025-05-27  7:22 UTC (permalink / raw)
  To: qemu-devel

On 5/26/25 19:10, Philippe Mathieu-Daudé wrote:
> Alternatively, since this is an error path:
> 
> -- >8 --
> diff --git a/hw/xen/xen-bus-helper.c b/hw/xen/xen-bus-helper.c
> index 288fad422be..1e49e60e147 100644
> --- a/hw/xen/xen-bus-helper.c
> +++ b/hw/xen/xen-bus-helper.c
> @@ -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;
>       }

Auto-free variables must be initialized.


r~


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

end of thread, other threads:[~2025-05-27  7:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-23 16:01 [PATCH] hw/xen: Fix trace_xs_node_read() params Liam Merwick
2025-05-23 16:46 ` [EXTERNAL] " David Woodhouse
2025-05-26 16:19 ` Anthony PERARD
2025-05-26 18:10 ` Philippe Mathieu-Daudé
2025-05-27  7:22   ` Richard Henderson

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