qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Henk van der Laak (LaakSoft)" via <qemu-devel@nongnu.org>
To: qemu-devel@nongnu.org
Cc: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>,
	Artyom Tarasenko <atar4qemu@gmail.com>
Subject: Patch: Sparc prevent segfault when dumping uninitialzed cpu state
Date: Mon, 3 Feb 2025 04:14:59 +0100	[thread overview]
Message-ID: <eb7fe8ed-e885-48c0-a36f-1f700bc692bf@laaksoft.nl> (raw)

Hi all, my first contribution. I checked code style, patch submission 
rules and did a manual test (details on request)

Synopsis:
It's a corner case, where a segfault occurs when logging Sparc CPU state 
in a partially initialized state.

No related bug report.

Open to harsh criticism ;-)

Regards,

Henk van der Laak <henk@laaksoft.nl>


Patch is based off 6fccaa2fba391815308a746d68f7fa197bc93586 
(origin/master) as of Sun Feb 2 11:09:10 2025 -0500
Signed-off-by: Henk van der Laak <henk@laaksoft.nl>

---
  target/sparc/cpu.c | 7 ++++++-
  1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c
index fbd38ec334..83aaa456fc 100644
--- a/target/sparc/cpu.c
+++ b/target/sparc/cpu.c
@@ -642,7 +642,12 @@ static void sparc_cpu_dump_state(CPUState *cs, FILE 
*f, int flags)
                               x == 0 ? 'o' : (x == 1 ? 'l' : 'i'),
                               i, i + REGS_PER_LINE - 1);
              }
-            qemu_fprintf(f, TARGET_FMT_lx " ", env->regwptr[i + x * 8]);
+            /*
+             * regwptr may not be initialized yet when logging
+             * e.g. cpu_reset
+             */
+            qemu_fprintf(f, TARGET_FMT_lx " ",
+                env->regwptr ? env->regwptr[i + x * 8] : 0);
              if (i % REGS_PER_LINE == REGS_PER_LINE - 1) {
                  qemu_fprintf(f, "\n");
              }
-- 
2.43.0



             reply	other threads:[~2025-02-03  3:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-03  3:14 Henk van der Laak (LaakSoft) via [this message]
2025-02-03  3:45 ` Patch: Sparc prevent segfault when dumping uninitialzed cpu state Richard Henderson
     [not found]   ` <a392d217-852c-46b4-84ef-d8ea5ad296c1@laaksoft.nl>
2025-02-03  4:10     ` Richard Henderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=eb7fe8ed-e885-48c0-a36f-1f700bc692bf@laaksoft.nl \
    --to=qemu-devel@nongnu.org \
    --cc=atar4qemu@gmail.com \
    --cc=henk@laaksoft.nl \
    --cc=mark.cave-ayland@ilande.co.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).