1 http://sourceware.org/ml/gdb-patches/2005-05/threads.html#00637
2 Proposed upstream but never committed upstream.
4 2005-06-09 Jeff Johnston <jjohnstn@redhat.com>
6 * gdb.base/gdbinit.exp: New testcase.
7 * gdb.base/gdbinit.sample: Sample .gdbinit for gdbinit.exp.
9 2005-06-08 Daniel Jacobowitz <dan@codesourcery.com>
10 Jeff Johnston <jjohnstn@redhat.com>
12 * Makefile.in (cli-cmds.o): Update.
13 * configure.in: Add check for getuid.
14 * configure: Regenerated.
16 * main.c (captured_main): Pass -1 to source_command when loading
18 * cli/cli-cmds.c: Include "gdb_stat.h" and <fcntl.h>.
19 (source_command): Update documentation. Check permissions if
22 Index: gdb-6.8.50.20090226/gdb/cli/cli-cmds.c
23 ===================================================================
24 --- gdb-6.8.50.20090226.orig/gdb/cli/cli-cmds.c 2009-02-27 00:04:32.000000000 +0100
25 +++ gdb-6.8.50.20090226/gdb/cli/cli-cmds.c 2009-02-28 07:17:49.000000000 +0100
30 +#include "gdb_stat.h"
34 @@ -466,7 +467,7 @@ source_script (char *file, int from_tty)
40 perror_with_name (file);
43 @@ -475,6 +476,29 @@ source_script (char *file, int from_tty)
50 + struct stat statbuf;
52 + if (fstat (fd, &statbuf) < 0)
55 + /* Do not do_cleanups (old_cleanups) as FILE is allocated there.
56 + perror_with_name calls error which should call the cleanups. */
57 + perror_with_name (file);
59 + if (statbuf.st_uid != getuid () || (statbuf.st_mode & S_IWOTH))
61 + /* FILE gets freed by do_cleanups (old_cleanups). */
62 + warning (_("not using untrusted file \"%s\""), file);
64 + do_cleanups (old_cleanups);
70 is_python = source_python;
71 if (strlen (file) > 3 && !strcmp (&file[strlen (file) - 3], ".py"))
73 @@ -486,6 +510,7 @@ source_script (char *file, int from_tty)
75 script_from_file (stream, file);
77 + /* FILE gets freed by do_cleanups (old_cleanups). */
78 do_cleanups (old_cleanups);
81 Index: gdb-6.8.50.20090226/gdb/testsuite/gdb.base/gdbinit.exp
82 ===================================================================
83 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
84 +++ gdb-6.8.50.20090226/gdb/testsuite/gdb.base/gdbinit.exp 2009-02-28 07:15:57.000000000 +0100
87 +# Free Software Foundation, Inc.
89 +# This program is free software; you can redistribute it and/or modify
90 +# it under the terms of the GNU General Public License as published by
91 +# the Free Software Foundation; either version 2 of the License, or
92 +# (at your option) any later version.
94 +# This program is distributed in the hope that it will be useful,
95 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
96 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
97 +# GNU General Public License for more details.
99 +# You should have received a copy of the GNU General Public License
100 +# along with this program; if not, write to the Free Software
101 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
103 +# Please email any bugs, comments, and/or additions to this file to:
104 +# bug-gdb@prep.ai.mit.edu
106 +# This file was written by Jeff Johnston <jjohnstn@redhat.com>.
108 +if $tracelevel then {
115 +# are we on a target board
116 +if [is_remote target] {
126 +global gdb_spawn_id;
128 +gdb_stop_suppressing_tests;
130 +verbose "Spawning $GDB -nw"
132 +if [info exists gdb_spawn_id] {
136 +if ![is_remote host] {
137 + if { [which $GDB] == 0 } then {
138 + perror "$GDB does not exist."
144 +remote_exec build "rm .gdbinit"
145 +remote_exec build "cp ${srcdir}/${subdir}/gdbinit.sample .gdbinit"
146 +remote_exec build "chmod 646 .gdbinit"
148 +set res [remote_spawn host "$GDB -nw [host_info gdb_opts]"];
149 +if { $res < 0 || $res == "" } {
150 + perror "Spawning $GDB failed."
154 + -re "warning: not using untrusted file.*\.gdbinit.*\[\r\n\]$gdb_prompt $" {
155 + pass "untrusted .gdbinit caught."
157 + -re "$gdb_prompt $" {
158 + fail "untrusted .gdbinit caught."
161 + fail "(timeout) untrusted .gdbinit caught."
165 +remote_exec build "chmod 644 .gdbinit"
166 +set res [remote_spawn host "$GDB -nw [host_info gdb_opts]"];
167 +if { $res < 0 || $res == "" } {
168 + perror "Spawning $GDB failed."
172 + -re "warning: not using untrusted file.*\.gdbinit.*\[\r\n\]$gdb_prompt $" {
173 + fail "trusted .gdbinit allowed."
175 + -re "in gdbinit.*$gdb_prompt $" {
176 + pass "trusted .gdbinit allowed."
179 + fail "(timeout) trusted .gdbinit allowed."
183 +remote_exec build "rm .gdbinit"
184 Index: gdb-6.8.50.20090226/gdb/testsuite/gdb.base/gdbinit.sample
185 ===================================================================
186 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
187 +++ gdb-6.8.50.20090226/gdb/testsuite/gdb.base/gdbinit.sample 2009-02-28 07:15:57.000000000 +0100
190 Index: gdb-6.8.50.20090226/gdb/main.c
191 ===================================================================
192 --- gdb-6.8.50.20090226.orig/gdb/main.c 2009-02-27 00:04:32.000000000 +0100
193 +++ gdb-6.8.50.20090226/gdb/main.c 2009-02-28 07:15:57.000000000 +0100
194 @@ -855,7 +855,7 @@ Excess command line arguments ignored. (
195 debugging or what directory you are in. */
197 if (home_gdbinit && !inhibit_gdbinit)
198 - catch_command_errors (source_script, home_gdbinit, 0, RETURN_MASK_ALL);
199 + catch_command_errors (source_script, home_gdbinit, -1, RETURN_MASK_ALL);
201 /* Now perform all the actions indicated by the arguments. */
203 @@ -924,7 +924,7 @@ Can't attach to process and specify a co
204 /* Read the .gdbinit file in the current directory, *if* it isn't
205 the same as the $HOME/.gdbinit file (it should exist, also). */
206 if (local_gdbinit && !inhibit_gdbinit)
207 - catch_command_errors (source_script, local_gdbinit, 0, RETURN_MASK_ALL);
208 + catch_command_errors (source_script, local_gdbinit, -1, RETURN_MASK_ALL);
210 for (i = 0; i < ncmd; i++)