]>
Commit | Line | Data |
---|---|---|
3a58abaf AM |
1 | http://sourceware.org/ml/gdb-patches/2005-05/threads.html#00637 |
2 | Proposed upstream but never committed upstream. | |
3 | ||
4 | 2005-06-09 Jeff Johnston <jjohnstn@redhat.com> | |
5 | ||
6 | * gdb.base/gdbinit.exp: New testcase. | |
7 | * gdb.base/gdbinit.sample: Sample .gdbinit for gdbinit.exp. | |
8 | ||
9 | 2005-06-08 Daniel Jacobowitz <dan@codesourcery.com> | |
10 | Jeff Johnston <jjohnstn@redhat.com> | |
11 | ||
12 | * Makefile.in (cli-cmds.o): Update. | |
13 | * configure.in: Add check for getuid. | |
14 | * configure: Regenerated. | |
15 | * config.in: Ditto. | |
16 | * main.c (captured_main): Pass -1 to source_command when loading | |
17 | gdbinit files. | |
18 | * cli/cli-cmds.c: Include "gdb_stat.h" and <fcntl.h>. | |
19 | (source_command): Update documentation. Check permissions if | |
20 | FROM_TTY is -1. | |
21 | ||
f412e1b4 | 22 | Index: gdb-7.4.50.20111218/gdb/cli/cli-cmds.c |
3a58abaf | 23 | =================================================================== |
f412e1b4 PS |
24 | --- gdb-7.4.50.20111218.orig/gdb/cli/cli-cmds.c 2011-12-16 22:17:42.000000000 +0100 |
25 | +++ gdb-7.4.50.20111218/gdb/cli/cli-cmds.c 2011-12-19 00:27:16.572468926 +0100 | |
26 | @@ -40,6 +40,7 @@ | |
3a58abaf AM |
27 | #include "source.h" |
28 | #include "disasm.h" | |
51a5ef0f | 29 | #include "tracepoint.h" |
3a58abaf AM |
30 | +#include "gdb_stat.h" |
31 | ||
32 | #include "ui-out.h" | |
33 | ||
f412e1b4 | 34 | @@ -485,7 +486,7 @@ show_script_ext_mode (struct ui_file *fi |
3a58abaf | 35 | |
51a5ef0f PS |
36 | int |
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) | |
40 | { | |
41 | char *file; | |
42 | int fd; | |
f412e1b4 | 43 | @@ -511,6 +512,32 @@ find_and_open_script (const char *script |
51a5ef0f | 44 | return 0; |
3a58abaf AM |
45 | } |
46 | ||
47 | +#ifdef HAVE_GETUID | |
48 | + if (from_tty == -1) | |
49 | + { | |
50 | + struct stat statbuf; | |
51 | + | |
52 | + if (fstat (fd, &statbuf) < 0) | |
53 | + { | |
51a5ef0f PS |
54 | + int save_errno = errno; |
55 | + | |
3a58abaf | 56 | + close (fd); |
51a5ef0f PS |
57 | + do_cleanups (old_cleanups); |
58 | + errno = save_errno; | |
59 | + return 0; | |
3a58abaf AM |
60 | + } |
61 | + if (statbuf.st_uid != getuid () || (statbuf.st_mode & S_IWOTH)) | |
62 | + { | |
63 | + /* FILE gets freed by do_cleanups (old_cleanups). */ | |
64 | + warning (_("not using untrusted file \"%s\""), file); | |
65 | + close (fd); | |
66 | + do_cleanups (old_cleanups); | |
51a5ef0f PS |
67 | + errno = EPERM; |
68 | + return 0; | |
3a58abaf AM |
69 | + } |
70 | + } | |
71 | +#endif | |
72 | + | |
3a58abaf | 73 | do_cleanups (old_cleanups); |
3a58abaf | 74 | |
51a5ef0f | 75 | *streamp = fdopen (fd, FOPEN_RT); |
f412e1b4 | 76 | @@ -572,13 +599,14 @@ source_script_with_search (const char *f |
51a5ef0f PS |
77 | if (file == NULL || *file == 0) |
78 | error (_("source command requires file name of file to source.")); | |
79 | ||
80 | - if (!find_and_open_script (file, search_path, &stream, &full_path)) | |
81 | + if (!find_and_open_script (file, search_path, &stream, &full_path, | |
82 | + from_tty)) | |
83 | { | |
f412e1b4 | 84 | /* The script wasn't found, or was otherwise inaccessible. |
6ed6bacf AM |
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. */ | |
51a5ef0f PS |
88 | - if (from_tty) |
89 | + if (from_tty > 0) | |
90 | perror_with_name (file); | |
91 | else | |
92 | return; | |
f412e1b4 | 93 | Index: gdb-7.4.50.20111218/gdb/testsuite/gdb.base/gdbinit.exp |
3a58abaf AM |
94 | =================================================================== |
95 | --- /dev/null 1970-01-01 00:00:00.000000000 +0000 | |
f412e1b4 | 96 | +++ gdb-7.4.50.20111218/gdb/testsuite/gdb.base/gdbinit.exp 2011-12-19 00:25:26.079891954 +0100 |
51a5ef0f | 97 | @@ -0,0 +1,91 @@ |
3a58abaf AM |
98 | +# Copyright 2005 |
99 | +# Free Software Foundation, Inc. | |
100 | + | |
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. | |
105 | +# | |
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. | |
110 | +# | |
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. | |
114 | + | |
115 | +# Please email any bugs, comments, and/or additions to this file to: | |
116 | +# bug-gdb@prep.ai.mit.edu | |
117 | + | |
118 | +# This file was written by Jeff Johnston <jjohnstn@redhat.com>. | |
119 | + | |
3a58abaf AM |
120 | +# are we on a target board |
121 | +if [is_remote target] { | |
122 | + return | |
123 | +} | |
124 | + | |
125 | + | |
126 | +global verbose | |
127 | +global GDB | |
128 | +global GDBFLAGS | |
129 | +global gdb_prompt | |
130 | +global timeout | |
131 | +global gdb_spawn_id; | |
132 | + | |
133 | +gdb_stop_suppressing_tests; | |
134 | + | |
135 | +verbose "Spawning $GDB -nw" | |
136 | + | |
137 | +if [info exists gdb_spawn_id] { | |
138 | + return 0; | |
139 | +} | |
140 | + | |
141 | +if ![is_remote host] { | |
142 | + if { [which $GDB] == 0 } then { | |
143 | + perror "$GDB does not exist." | |
144 | + exit 1 | |
145 | + } | |
146 | +} | |
147 | + | |
148 | +set env(HOME) [pwd] | |
149 | +remote_exec build "rm .gdbinit" | |
150 | +remote_exec build "cp ${srcdir}/${subdir}/gdbinit.sample .gdbinit" | |
151 | +remote_exec build "chmod 646 .gdbinit" | |
152 | + | |
153 | +set res [remote_spawn host "$GDB -nw [host_info gdb_opts]"]; | |
154 | +if { $res < 0 || $res == "" } { | |
155 | + perror "Spawning $GDB failed." | |
156 | + return 1; | |
157 | +} | |
158 | +gdb_expect 360 { | |
159 | + -re "warning: not using untrusted file.*\.gdbinit.*\[\r\n\]$gdb_prompt $" { | |
160 | + pass "untrusted .gdbinit caught." | |
161 | + } | |
162 | + -re "$gdb_prompt $" { | |
163 | + fail "untrusted .gdbinit caught." | |
164 | + } | |
165 | + timeout { | |
166 | + fail "(timeout) untrusted .gdbinit caught." | |
167 | + } | |
168 | +} | |
169 | + | |
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." | |
174 | + return 1; | |
175 | +} | |
176 | +gdb_expect 360 { | |
177 | + -re "warning: not using untrusted file.*\.gdbinit.*\[\r\n\]$gdb_prompt $" { | |
178 | + fail "trusted .gdbinit allowed." | |
179 | + } | |
180 | + -re "in gdbinit.*$gdb_prompt $" { | |
181 | + pass "trusted .gdbinit allowed." | |
182 | + } | |
183 | + timeout { | |
184 | + fail "(timeout) trusted .gdbinit allowed." | |
185 | + } | |
186 | +} | |
187 | + | |
188 | +remote_exec build "rm .gdbinit" | |
f412e1b4 | 189 | Index: gdb-7.4.50.20111218/gdb/testsuite/gdb.base/gdbinit.sample |
3a58abaf AM |
190 | =================================================================== |
191 | --- /dev/null 1970-01-01 00:00:00.000000000 +0000 | |
f412e1b4 | 192 | +++ gdb-7.4.50.20111218/gdb/testsuite/gdb.base/gdbinit.sample 2011-12-19 00:25:26.079891954 +0100 |
3a58abaf AM |
193 | @@ -0,0 +1 @@ |
194 | +echo "\nin gdbinit" | |
f412e1b4 | 195 | Index: gdb-7.4.50.20111218/gdb/main.c |
3a58abaf | 196 | =================================================================== |
f412e1b4 PS |
197 | --- gdb-7.4.50.20111218.orig/gdb/main.c 2011-11-05 18:08:30.000000000 +0100 |
198 | +++ gdb-7.4.50.20111218/gdb/main.c 2011-12-19 00:25:26.080891950 +0100 | |
199 | @@ -822,7 +822,7 @@ captured_main (void *data) | |
3a58abaf AM |
200 | debugging or what directory you are in. */ |
201 | ||
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); | |
205 | ||
206 | /* Now perform all the actions indicated by the arguments. */ | |
207 | if (cdarg != NULL) | |
f412e1b4 | 208 | @@ -901,7 +901,7 @@ captured_main (void *data) |
3a58abaf AM |
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); | |
214 | ||
51a5ef0f PS |
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. | |
f412e1b4 | 217 | Index: gdb-7.4.50.20111218/gdb/python/py-auto-load.c |
51a5ef0f | 218 | =================================================================== |
f412e1b4 PS |
219 | --- gdb-7.4.50.20111218.orig/gdb/python/py-auto-load.c 2011-12-10 23:51:47.000000000 +0100 |
220 | +++ gdb-7.4.50.20111218/gdb/python/py-auto-load.c 2011-12-19 00:25:26.080891950 +0100 | |
221 | @@ -284,7 +284,7 @@ source_section_scripts (struct objfile * | |
51a5ef0f PS |
222 | } |
223 | ||
224 | opened = find_and_open_script (file, 1 /*search_path*/, | |
225 | - &stream, &full_path); | |
226 | + &stream, &full_path, 1 /* from_tty */); | |
227 | ||
f412e1b4 PS |
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.4.50.20111218/gdb/cli/cli-cmds.h | |
51a5ef0f | 231 | =================================================================== |
f412e1b4 PS |
232 | --- gdb-7.4.50.20111218.orig/gdb/cli/cli-cmds.h 2011-11-01 15:51:23.000000000 +0100 |
233 | +++ gdb-7.4.50.20111218/gdb/cli/cli-cmds.h 2011-12-19 00:25:26.080891950 +0100 | |
234 | @@ -129,7 +129,8 @@ extern void source_script (char *, int); | |
51a5ef0f PS |
235 | /* Exported to objfiles.c. */ |
236 | ||
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, | |
240 | + int from_tty); | |
241 | ||
242 | /* Command tracing state. */ | |
243 |