From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26919 invoked by alias); 13 Jan 2002 21:10:17 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 26880 invoked from network); 13 Jan 2002 21:10:16 -0000 Received: from unknown (HELO localhost.cygnus.com) (24.114.42.213) by sources.redhat.com with SMTP; 13 Jan 2002 21:10:16 -0000 Received: from cygnus.com (localhost [127.0.0.1]) by localhost.cygnus.com (Postfix) with ESMTP id 682763D1F; Sun, 13 Jan 2002 16:10:05 -0500 (EST) Message-ID: <3C41F7AD.7040708@cygnus.com> Date: Sun, 13 Jan 2002 13:10:00 -0000 From: Andrew Cagney User-Agent: Mozilla/5.0 (X11; U; NetBSD macppc; en-US; rv:0.9.7) Gecko/20020103 X-Accept-Language: en-us MIME-Version: 1.0 To: Petr Ledvina Cc: gdb-patches@sources.redhat.com Subject: Re: bug in gdb/target.c:target_signal_to_name References: Content-Type: multipart/mixed; boundary="------------050003060900050001000300" X-SW-Source: 2002-01/txt/msg00360.txt.bz2 This is a multi-part message in MIME format. --------------050003060900050001000300 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Content-length: 776 > 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 --------------050003060900050001000300 Content-Type: text/plain; name="diffs" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="diffs" Content-length: 1091 2002-01-13 Andrew Cagney From Petr Ledvina : * 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. */ --------------050003060900050001000300--