From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8073 invoked by alias); 7 Feb 2006 19:39:36 -0000 Received: (qmail 7770 invoked by uid 22791); 7 Feb 2006 19:39:35 -0000 X-Spam-Check-By: sourceware.org Received: from nevyn.them.org (HELO nevyn.them.org) (66.93.172.17) by sourceware.org (qpsmtpd/0.31.1) with ESMTP; Tue, 07 Feb 2006 19:39:34 +0000 Received: from drow by nevyn.them.org with local (Exim 4.54) id 1F6YgW-0007Zr-5w for gdb-patches@sourceware.org; Tue, 07 Feb 2006 14:39:32 -0500 Date: Tue, 07 Feb 2006 19:39:00 -0000 From: Daniel Jacobowitz To: gdb-patches@sourceware.org Subject: Prevent crashes using $arg0 Message-ID: <20060207193932.GA28960@nevyn.them.org> Mail-Followup-To: gdb-patches@sourceware.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.8i X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2006-02/txt/msg00153.txt.bz2 This patch fixes a crash Andrew Stubbs reported: if 1 == 1 print $arg0 end The new response is: $arg0 used outside of any user function Comments? Not thrilled with the wording of the error, but it'll do. -- Daniel Jacobowitz CodeSourcery 2006-02-07 Daniel Jacobowitz * cli/cli-script.c (insert_args): Handle NULL user_args. 2006-02-07 Daniel Jacobowitz * gdb.base/commands.exp (stray_arg0_test): New test. Index: cli/cli-script.c =================================================================== RCS file: /cvs/src/src/gdb/cli/cli-script.c,v retrieving revision 1.32 diff -u -p -r1.32 cli-script.c --- cli/cli-script.c 17 Dec 2005 22:40:17 -0000 1.32 +++ cli/cli-script.c 7 Feb 2006 19:37:18 -0000 @@ -1,8 +1,8 @@ /* GDB CLI command scripting. Copyright (c) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, - 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2004, 2005 Free - Software Foundation, Inc. + 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2004, 2005, 2006 + Free Software Foundation, Inc. This file is part of GDB. @@ -598,7 +598,9 @@ insert_args (char *line) len += p - line; i = p[4] - '0'; - if (p[4] == 'c') + if (user_args == NULL) + error (_("%.5s used outside of any user function"), p); + else if (p[4] == 'c') { /* $argc. Number will be <=10. */ len += user_args->count == 10 ? 2 : 1; Index: testsuite/gdb.base/commands.exp =================================================================== RCS file: /cvs/src/src/gdb/testsuite/gdb.base/commands.exp,v retrieving revision 1.14 diff -u -p -r1.14 commands.exp --- testsuite/gdb.base/commands.exp 7 Mar 2005 21:36:16 -0000 1.14 +++ testsuite/gdb.base/commands.exp 7 Feb 2006 19:37:19 -0000 @@ -1,5 +1,5 @@ # Copyright 1988, 1990, 1991, 1992, 1994, 1995, 1997, 1998, 1999, 2000, -# 2001, 2002, 2003 Free Software Foundation, Inc. +# 2001, 2002, 2003, 2005, 2006 Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -563,6 +563,12 @@ proc temporary_breakpoint_commands {} { timeout { fail "(timeout) run factorial until temporary breakpoint" } } } + +proc stray_arg0_test { } { + gdb_test "if 1 == 1\nprint \$arg0\nend" \ + "\\\$arg0 used outside of any user function" \ + "stray_arg0_test #1" +} gdbvar_simple_if_test gdbvar_simple_while_test @@ -579,3 +585,4 @@ test_command_prompt_position deprecated_command_test bp_deleted_in_command_test temporary_breakpoint_commands +stray_arg0_test