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-7.3.50.20110722/gdb/cli/cli-cmds.c
23 ===================================================================
24 --- gdb-7.3.50.20110722.orig/gdb/cli/cli-cmds.c 2011-06-07 19:26:46.000000000 +0200
25 +++ gdb-7.3.50.20110722/gdb/cli/cli-cmds.c 2011-07-22 19:14:25.000000000 +0200
29 #include "tracepoint.h"
30 +#include "gdb_stat.h"
34 @@ -489,7 +490,7 @@ show_script_ext_mode (struct ui_file *fi
37 find_and_open_script (const char *script_file, int search_path,
38 - FILE **streamp, char **full_pathp)
39 + FILE **streamp, char **full_pathp, int from_tty)
43 @@ -515,6 +516,32 @@ find_and_open_script (const char *script
50 + struct stat statbuf;
52 + if (fstat (fd, &statbuf) < 0)
54 + int save_errno = errno;
57 + do_cleanups (old_cleanups);
61 + if (statbuf.st_uid != getuid () || (statbuf.st_mode & S_IWOTH))
63 + /* FILE gets freed by do_cleanups (old_cleanups). */
64 + warning (_("not using untrusted file \"%s\""), file);
66 + do_cleanups (old_cleanups);
73 do_cleanups (old_cleanups);
75 *streamp = fdopen (fd, FOPEN_RT);
76 @@ -574,13 +601,14 @@ source_script_with_search (const char *f
77 if (file == NULL || *file == 0)
78 error (_("source command requires file name of file to source."));
80 - if (!find_and_open_script (file, search_path, &stream, &full_path))
81 + if (!find_and_open_script (file, search_path, &stream, &full_path,
84 /* The script wasn't found, or was otherwise inaccessible.
85 If the source command was invoked interactively, throw an
86 error. Otherwise (e.g. if it was invoked by a script),
87 silently ignore the error. */
90 perror_with_name (file);
93 Index: gdb-7.3.50.20110722/gdb/testsuite/gdb.base/gdbinit.exp
94 ===================================================================
95 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
96 +++ gdb-7.3.50.20110722/gdb/testsuite/gdb.base/gdbinit.exp 2011-07-22 19:14:25.000000000 +0200
99 +# Free Software Foundation, Inc.
101 +# This program is free software; you can redistribute it and/or modify
102 +# it under the terms of the GNU General Public License as published by
103 +# the Free Software Foundation; either version 2 of the License, or
104 +# (at your option) any later version.
106 +# This program is distributed in the hope that it will be useful,
107 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
108 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
109 +# GNU General Public License for more details.
111 +# You should have received a copy of the GNU General Public License
112 +# along with this program; if not, write to the Free Software
113 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
115 +# Please email any bugs, comments, and/or additions to this file to:
116 +# bug-gdb@prep.ai.mit.edu
118 +# This file was written by Jeff Johnston <jjohnstn@redhat.com>.
120 +# are we on a target board
121 +if [is_remote target] {
131 +global gdb_spawn_id;
133 +gdb_stop_suppressing_tests;
135 +verbose "Spawning $GDB -nw"
137 +if [info exists gdb_spawn_id] {
141 +if ![is_remote host] {
142 + if { [which $GDB] == 0 } then {
143 + perror "$GDB does not exist."
149 +remote_exec build "rm .gdbinit"
150 +remote_exec build "cp ${srcdir}/${subdir}/gdbinit.sample .gdbinit"
151 +remote_exec build "chmod 646 .gdbinit"
153 +set res [remote_spawn host "$GDB -nw [host_info gdb_opts]"];
154 +if { $res < 0 || $res == "" } {
155 + perror "Spawning $GDB failed."
159 + -re "warning: not using untrusted file.*\.gdbinit.*\[\r\n\]$gdb_prompt $" {
160 + pass "untrusted .gdbinit caught."
162 + -re "$gdb_prompt $" {
163 + fail "untrusted .gdbinit caught."
166 + fail "(timeout) untrusted .gdbinit caught."
170 +remote_exec build "chmod 644 .gdbinit"
171 +set res [remote_spawn host "$GDB -nw [host_info gdb_opts]"];
172 +if { $res < 0 || $res == "" } {
173 + perror "Spawning $GDB failed."
177 + -re "warning: not using untrusted file.*\.gdbinit.*\[\r\n\]$gdb_prompt $" {
178 + fail "trusted .gdbinit allowed."
180 + -re "in gdbinit.*$gdb_prompt $" {
181 + pass "trusted .gdbinit allowed."
184 + fail "(timeout) trusted .gdbinit allowed."
188 +remote_exec build "rm .gdbinit"
189 Index: gdb-7.3.50.20110722/gdb/testsuite/gdb.base/gdbinit.sample
190 ===================================================================
191 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
192 +++ gdb-7.3.50.20110722/gdb/testsuite/gdb.base/gdbinit.sample 2011-07-22 19:14:25.000000000 +0200
195 Index: gdb-7.3.50.20110722/gdb/main.c
196 ===================================================================
197 --- gdb-7.3.50.20110722.orig/gdb/main.c 2011-07-22 19:08:19.000000000 +0200
198 +++ gdb-7.3.50.20110722/gdb/main.c 2011-07-22 19:14:25.000000000 +0200
199 @@ -849,7 +849,7 @@ captured_main (void *data)
200 debugging or what directory you are in. */
202 if (home_gdbinit && !inhibit_gdbinit)
203 - catch_command_errors (source_script, home_gdbinit, 0, RETURN_MASK_ALL);
204 + catch_command_errors (source_script, home_gdbinit, -1, RETURN_MASK_ALL);
206 /* Now perform all the actions indicated by the arguments. */
208 @@ -928,7 +928,7 @@ captured_main (void *data)
209 /* Read the .gdbinit file in the current directory, *if* it isn't
210 the same as the $HOME/.gdbinit file (it should exist, also). */
211 if (local_gdbinit && !inhibit_gdbinit)
212 - catch_command_errors (source_script, local_gdbinit, 0, RETURN_MASK_ALL);
213 + catch_command_errors (source_script, local_gdbinit, -1, RETURN_MASK_ALL);
215 /* Now that all .gdbinit's have been read and all -d options have been
216 processed, we can read any scripts mentioned in SYMARG.
217 Index: gdb-7.3.50.20110722/gdb/python/py-auto-load.c
218 ===================================================================
219 --- gdb-7.3.50.20110722.orig/gdb/python/py-auto-load.c 2011-05-16 18:33:57.000000000 +0200
220 +++ gdb-7.3.50.20110722/gdb/python/py-auto-load.c 2011-07-22 19:14:54.000000000 +0200
221 @@ -284,7 +284,7 @@ source_section_scripts (struct objfile *
224 opened = find_and_open_script (file, 1 /*search_path*/,
225 - &stream, &full_path);
226 + &stream, &full_path, 1 /* from_tty */);
228 /* If one script isn't found it's not uncommon for more to not be
229 found either. We don't want to print an error message for each
230 Index: gdb-7.3.50.20110722/gdb/cli/cli-cmds.h
231 ===================================================================
232 --- gdb-7.3.50.20110722.orig/gdb/cli/cli-cmds.h 2011-01-01 16:33:20.000000000 +0100
233 +++ gdb-7.3.50.20110722/gdb/cli/cli-cmds.h 2011-07-22 19:14:25.000000000 +0200
234 @@ -127,7 +127,8 @@ extern void source_script (char *, int);
235 /* Exported to objfiles.c. */
237 extern int find_and_open_script (const char *file, int search_path,
238 - FILE **streamp, char **full_path);
239 + FILE **streamp, char **full_path,
242 /* Command tracing state. */