From: "Roger Sayle" <roger@nextmovesoftware.com>
To: <gdb-patches@sourceware.org>
Cc: "'Hans-Peter Nilsson'" <hp@axis.com>
Subject: [PATCH] Avoid seg fault in sim/cris/sim-if.c
Date: Sat, 1 Aug 2026 21:50:17 +0100 [thread overview]
Message-ID: <006501dd21f7$5fa6ab60$1ef40220$@nextmovesoftware.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 435 bytes --]
Typing "target sim" in GDB built with --target=cris-elf, crashes immediately
after being launched with "gdb ./a.out". The issue is that STATE_PROG_ARGV
may return NULL, and this isn't tested before dereferencing the pointer.
If approved, please could someone commit this for me.
Thanks in advance.
2026-08-01 Roger Sayle <roger@nextmovesoftware.com>
ChangeLog
* sim/cris/sim-if.c (sim_open): Check that prog_argv isn't NULL.
[-- Attachment #2: patchgd.txt --]
[-- Type: text/plain, Size: 597 bytes --]
diff --git a/sim/cris/sim-if.c b/sim/cris/sim-if.c
index 12c80983208..3babbb058b7 100644
--- a/sim/cris/sim-if.c
+++ b/sim/cris/sim-if.c
@@ -770,8 +770,9 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
for (envc = 0; environ[envc] != NULL; envc++)
len += strlen (environ[envc]) + 1;
- for (i = 0; prog_argv[i] != NULL; my_argc++, i++)
- len += strlen (prog_argv[i]) + 1;
+ if (prog_argv != NULL)
+ for (i = 0; prog_argv[i] != NULL; my_argc++, i++)
+ len += strlen (prog_argv[i]) + 1;
envstart = (envtop - len) & ~8191;
next reply other threads:[~2026-08-01 20:50 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-01 20:50 Roger Sayle [this message]
2026-08-03 12:10 ` Andrew Burgess
[not found] ` <009501dd2343$a20cc5f0$e62651d0$@nextmovesoftware.com>
2026-08-10 14:07 ` Hans-Peter Nilsson
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='006501dd21f7$5fa6ab60$1ef40220$@nextmovesoftware.com' \
--to=roger@nextmovesoftware.com \
--cc=gdb-patches@sourceware.org \
--cc=hp@axis.com \
/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