[PATCH] Avoid seg fault in sim/cris/sim-if.c
"Roger Sayle" <[email protected]> Sat, 1 Aug 2026 21:50:17 +0100
| Newsgroups | gmane.comp.gdb.patches |
|---|---|
| Message-ID | <[email protected]> |
This is a multipart message in MIME format. ------=_NextPart_000_0066_01DD21FF.C16DAB70 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 <[email protected]> ChangeLog * sim/cris/sim-if.c (sim_open): Check that prog_argv isn't NULL. ------=_NextPart_000_0066_01DD21FF.C16DAB70 Content-Type: text/plain; name="patchgd.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="patchgd.txt" diff --git a/sim/cris/sim-if.c b/sim/cris/sim-if.c=0A= index 12c80983208..3babbb058b7 100644=0A= --- a/sim/cris/sim-if.c=0A= +++ b/sim/cris/sim-if.c=0A= @@ -770,8 +770,9 @@ sim_open (SIM_OPEN_KIND kind, host_callback = *callback, struct bfd *abfd,=0A= for (envc =3D 0; environ[envc] !=3D NULL; envc++)=0A= len +=3D strlen (environ[envc]) + 1;=0A= =0A= - for (i =3D 0; prog_argv[i] !=3D NULL; my_argc++, i++)=0A= - len +=3D strlen (prog_argv[i]) + 1;=0A= + if (prog_argv !=3D NULL)=0A= + for (i =3D 0; prog_argv[i] !=3D NULL; my_argc++, i++)=0A= + len +=3D strlen (prog_argv[i]) + 1;=0A= =0A= envstart =3D (envtop - len) & ~8191;=0A= =0A= ------=_NextPart_000_0066_01DD21FF.C16DAB70--