* Re: bug in gdb/target.c:target_signal_to_name [not found] <Pine.OSF.4.33.0111301833160.4557-100000@eryx1.zcu.cz> @ 2002-01-13 13:10 ` Andrew Cagney 2002-01-13 13:13 ` Daniel Jacobowitz 0 siblings, 1 reply; 3+ messages in thread From: Andrew Cagney @ 2002-01-13 13:10 UTC (permalink / raw) To: Petr Ledvina; +Cc: gdb-patches [-- Attachment #1: Type: text/plain, Size: 776 bytes --] > When remote target returns some invalid signal, gdb vill crash with > segfault. The problem seems to be in function target_signal_to_name, > which doesn't check, if signal is in bounds and returns invalid name. > > This version will (at least) not segfault: > > /* Return the name for a signal. */ > char * > target_signal_to_name (sig) > enum target_signal sig; > { > if (sig == TARGET_SIGNAL_UNKNOWN) > /* I think the code which prints this will always print it along with > the string, so no need to be verbose. */ > return "?"; > if ((sig >= TARGET_SIGNAL_FIRST) && (sig <= TARGET_SIGNAL_LAST)) > return signals[sig].name; > else > return signals[TARGET_SIGNAL_UNKNOWN].name; > } Thanks. I've committed the attached. Andrew [-- Attachment #2: diffs --] [-- Type: text/plain, Size: 1091 bytes --] 2002-01-13 Andrew Cagney <ac131313@redhat.com> From Petr Ledvina <ledvinap@kae.zcu.cz>: * signals.c (target_signal_to_name): Verify that SIG is within the bounds of the signals array. Index: signals.c =================================================================== RCS file: /cvs/src/src/gdb/signals.c,v retrieving revision 1.1 diff -p -r1.1 signals.c *** signals.c 2001/07/19 18:09:11 1.1 --- signals.c 2002/01/13 21:04:30 *************** target_signal_to_name (enum target_signa *** 214,220 **** /* I think the code which prints this will always print it along with the string, so no need to be verbose. */ return "?"; ! return signals[sig].name; } /* Given a name, return its signal. */ --- 214,223 ---- /* I think the code which prints this will always print it along with the string, so no need to be verbose. */ return "?"; ! else if ((sig >= TARGET_SIGNAL_FIRST) && (sig <= TARGET_SIGNAL_LAST)) ! return signals[sig].name; ! else ! return signals[sig].name; } /* Given a name, return its signal. */ ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: bug in gdb/target.c:target_signal_to_name 2002-01-13 13:10 ` bug in gdb/target.c:target_signal_to_name Andrew Cagney @ 2002-01-13 13:13 ` Daniel Jacobowitz 2002-01-13 13:55 ` Andrew Cagney 0 siblings, 1 reply; 3+ messages in thread From: Daniel Jacobowitz @ 2002-01-13 13:13 UTC (permalink / raw) To: Andrew Cagney; +Cc: Petr Ledvina, gdb-patches On Sun, Jan 13, 2002 at 04:10:05PM -0500, Andrew Cagney wrote: > --- 214,223 ---- > /* I think the code which prints this will always print it along with > the string, so no need to be verbose. */ > return "?"; > ! else if ((sig >= TARGET_SIGNAL_FIRST) && (sig <= TARGET_SIGNAL_LAST)) > ! return signals[sig].name; > ! else > ! return signals[sig].name; > } > > /* Given a name, return its signal. */ That's probably not what you meant to commit, since both cases are the same. -- Daniel Jacobowitz Carnegie Mellon University MontaVista Software Debian GNU/Linux Developer ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: bug in gdb/target.c:target_signal_to_name 2002-01-13 13:13 ` Daniel Jacobowitz @ 2002-01-13 13:55 ` Andrew Cagney 0 siblings, 0 replies; 3+ messages in thread From: Andrew Cagney @ 2002-01-13 13:55 UTC (permalink / raw) To: Daniel Jacobowitz; +Cc: Petr Ledvina, gdb-patches [-- Attachment #1: Type: text/plain, Size: 622 bytes --] > On Sun, Jan 13, 2002 at 04:10:05PM -0500, Andrew Cagney wrote: > >> --- 214,223 ---- >> /* I think the code which prints this will always print it along with >> the string, so no need to be verbose. */ >> return "?"; >> ! else if ((sig >= TARGET_SIGNAL_FIRST) && (sig <= TARGET_SIGNAL_LAST)) >> ! return signals[sig].name; >> ! else >> ! return signals[sig].name; >> } >> > /* Given a name, return its signal. */ > > > That's probably not what you meant to commit, since both cases are the > same. Er, no. Lets try the attached. Turns out that signals[TARGET_SIGNAL_UNKNOWN].name is NULL. Andrew [-- Attachment #2: diffs --] [-- Type: text/plain, Size: 1352 bytes --] 2002-01-13 Andrew Cagney <ac131313@redhat.com> * signals.c (target_signal_to_name): Rewrite. Only use signals[].name when in bounds and non-NULL. Index: signals.c =================================================================== RCS file: /cvs/src/src/gdb/signals.c,v retrieving revision 1.2 diff -p -r1.2 signals.c *** signals.c 2002/01/13 21:11:38 1.2 --- signals.c 2002/01/13 21:51:26 *************** target_signal_to_string (enum target_sig *** 210,223 **** char * target_signal_to_name (enum target_signal sig) { ! if (sig == TARGET_SIGNAL_UNKNOWN) ! /* I think the code which prints this will always print it along with ! the string, so no need to be verbose. */ ! return "?"; ! else if ((sig >= TARGET_SIGNAL_FIRST) && (sig <= TARGET_SIGNAL_LAST)) return signals[sig].name; else ! return signals[sig].name; } /* Given a name, return its signal. */ --- 210,222 ---- char * target_signal_to_name (enum target_signal sig) { ! if ((sig >= TARGET_SIGNAL_FIRST) && (sig <= TARGET_SIGNAL_LAST) ! && signals[sig].name != NULL) return signals[sig].name; else ! /* I think the code which prints this will always print it along ! with the string, so no need to be verbose (very old comment). */ ! return "?"; } /* Given a name, return its signal. */ ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2002-01-13 21:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <Pine.OSF.4.33.0111301833160.4557-100000@eryx1.zcu.cz>
2002-01-13 13:10 ` bug in gdb/target.c:target_signal_to_name Andrew Cagney
2002-01-13 13:13 ` Daniel Jacobowitz
2002-01-13 13:55 ` Andrew Cagney
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox