All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] error: Rewrite &error_warn with ERRP_GUARD()
@ 2025-08-03 14:52 Akihiko Odaki
  2025-08-08  8:13 ` Markus Armbruster
  0 siblings, 1 reply; 2+ messages in thread
From: Akihiko Odaki @ 2025-08-03 14:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: Markus Armbruster, Michael Roth, Akihiko Odaki

Without rewrite, an warning message may be printed before
error_prepend(); in such a scenario, error_prepend() will results in
NULL dereference because error_warn is NULL.

Rewrite &error_warn with ERRP_GUARD() to make sure error_prepend() is
reflected to printed messages and to avoid NULL dereference.

Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
---
 include/qapi/error.h | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/include/qapi/error.h b/include/qapi/error.h
index 41e38163804904874e5d114b699a3e2a93d3fc6d..4fa04980c2fd110aa68ced020dd1ec8a83d7d957 100644
--- a/include/qapi/error.h
+++ b/include/qapi/error.h
@@ -505,20 +505,20 @@ void error_set_internal(Error **errp,
  * It is safe to use even when it's not needed, but please avoid
  * cluttering the source with useless code.
  *
- * If @errp is NULL or &error_fatal, rewrite it to point to a local
- * Error variable, which will be automatically propagated to the
- * original @errp on function exit.
+ * If @errp is NULL, &error_fatal, or &error_warn, rewrite it to point
+ * to a local Error variable, which will be automatically propagated to
+ * the original @errp on function exit.
  *
  * Note: &error_abort is not rewritten, because that would move the
  * abort from the place where the error is created to the place where
  * it's propagated.
  */
-#define ERRP_GUARD()                                            \
-    g_auto(ErrorPropagator) _auto_errp_prop = {.errp = errp};   \
-    do {                                                        \
-        if (!errp || errp == &error_fatal) {                    \
-            errp = &_auto_errp_prop.local_err;                  \
-        }                                                       \
+#define ERRP_GUARD()                                                \
+    g_auto(ErrorPropagator) _auto_errp_prop = {.errp = errp};       \
+    do {                                                            \
+        if (!errp || errp == &error_fatal || errp == &error_warn) { \
+            errp = &_auto_errp_prop.local_err;                      \
+        }                                                           \
     } while (0)
 
 typedef struct ErrorPropagator {

---
base-commit: f0737158b483e7ec2b2512145aeab888b85cc1f7
change-id: 20250803-errp-e54c8242e2dd

Best regards,
-- 
Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>



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

* Re: [PATCH] error: Rewrite &error_warn with ERRP_GUARD()
  2025-08-03 14:52 [PATCH] error: Rewrite &error_warn with ERRP_GUARD() Akihiko Odaki
@ 2025-08-08  8:13 ` Markus Armbruster
  0 siblings, 0 replies; 2+ messages in thread
From: Markus Armbruster @ 2025-08-08  8:13 UTC (permalink / raw)
  To: Akihiko Odaki; +Cc: qemu-devel, Michael Roth, Marc-André Lureau

Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> writes:

> Without rewrite, an warning message may be printed before
> error_prepend(); in such a scenario, error_prepend() will results in
> NULL dereference because error_warn is NULL.
>
> Rewrite &error_warn with ERRP_GUARD() to make sure error_prepend() is
> reflected to printed messages and to avoid NULL dereference.
>
> Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>

You're right.  Needs

  Fixes: 3ffef1a55ca3 (error: add global &error_warn destination)

However, there's still more to fix up, and &error_warn is rarely used.
I just posted patches to delete it instead:

    [PATCH 00/12] Error reporting cleanup, a fix, and &error_warn removal

Thank you!



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

end of thread, other threads:[~2025-08-08  8:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-03 14:52 [PATCH] error: Rewrite &error_warn with ERRP_GUARD() Akihiko Odaki
2025-08-08  8:13 ` Markus Armbruster

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.