From 13bedeb212e3173f8de60286a38f8a5cb57affd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Date: Wed, 24 Sep 2025 18:55:21 +0100 Subject: [PATCH] util: fix interleaving of error prefixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The vreport() function will optionally emit an prefix for error messages which is output to stderr incrementally. In the event that two vreport() calls execute concurrently, there is a risk that the prefix output will interleave. To address this it is required to take a lock on 'stderr' when outputting errors. Reported-by: Markus Armbruster Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson Reviewed-by: Markus Armbruster Signed-off-by: Daniel P. Berrangé --- util/error-report.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/util/error-report.c b/util/error-report.c index 6b9e592bc1..bbea49a55d 100644 --- a/util/error-report.c +++ b/util/error-report.c @@ -233,6 +233,9 @@ static void vreport(report_type type, const char *fmt, va_list ap) if (monitor_cur_is_qmp()) { cur = NULL; } + if (!cur) { + qemu_flockfile(stderr); + } if (message_with_timestamp && !cur) { timestr = real_time_iso8601(); @@ -260,6 +263,10 @@ static void vreport(report_type type, const char *fmt, va_list ap) error_vprintf_mon(cur, fmt, ap); error_printf_mon(cur, "\n"); + + if (!cur) { + qemu_funlockfile(stderr); + } } /*