2008-12-14 14:05:20 +00:00
|
|
|
http://sourceware.org/ml/gdb-patches/2005-05/threads.html#00637
|
|
|
|
Proposed upstream but never committed upstream.
|
|
|
|
|
2005-06-10 20:50:21 +00:00
|
|
|
2005-06-09 Jeff Johnston <jjohnstn@redhat.com>
|
|
|
|
|
|
|
|
* gdb.base/gdbinit.exp: New testcase.
|
|
|
|
* gdb.base/gdbinit.sample: Sample .gdbinit for gdbinit.exp.
|
|
|
|
|
|
|
|
2005-06-08 Daniel Jacobowitz <dan@codesourcery.com>
|
|
|
|
Jeff Johnston <jjohnstn@redhat.com>
|
|
|
|
|
|
|
|
* Makefile.in (cli-cmds.o): Update.
|
|
|
|
* configure.in: Add check for getuid.
|
|
|
|
* configure: Regenerated.
|
|
|
|
* config.in: Ditto.
|
|
|
|
* main.c (captured_main): Pass -1 to source_command when loading
|
|
|
|
gdbinit files.
|
|
|
|
* cli/cli-cmds.c: Include "gdb_stat.h" and <fcntl.h>.
|
|
|
|
(source_command): Update documentation. Check permissions if
|
|
|
|
FROM_TTY is -1.
|
|
|
|
|
2012-01-03 15:00:12 +00:00
|
|
|
Index: gdb-7.4.50.20111218/gdb/cli/cli-cmds.c
|
2006-07-11 06:33:02 +00:00
|
|
|
===================================================================
|
2012-01-03 15:00:12 +00:00
|
|
|
--- gdb-7.4.50.20111218.orig/gdb/cli/cli-cmds.c 2011-12-16 22:17:42.000000000 +0100
|
|
|
|
+++ gdb-7.4.50.20111218/gdb/cli/cli-cmds.c 2011-12-19 00:27:16.572468926 +0100
|
|
|
|
@@ -40,6 +40,7 @@
|
2005-06-10 20:50:21 +00:00
|
|
|
#include "source.h"
|
|
|
|
#include "disasm.h"
|
2010-07-21 21:30:20 +00:00
|
|
|
#include "tracepoint.h"
|
2005-06-10 20:50:21 +00:00
|
|
|
+#include "gdb_stat.h"
|
|
|
|
|
|
|
|
#include "ui-out.h"
|
2010-07-21 21:30:20 +00:00
|
|
|
|
2012-01-03 15:00:12 +00:00
|
|
|
@@ -485,7 +486,7 @@ show_script_ext_mode (struct ui_file *fi
|
2010-07-21 21:30:20 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
find_and_open_script (const char *script_file, int search_path,
|
|
|
|
- FILE **streamp, char **full_pathp)
|
|
|
|
+ FILE **streamp, char **full_pathp, int from_tty)
|
|
|
|
{
|
|
|
|
char *file;
|
|
|
|
int fd;
|
2012-01-03 15:00:12 +00:00
|
|
|
@@ -511,6 +512,32 @@ find_and_open_script (const char *script
|
2010-07-21 21:30:20 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2005-06-10 20:50:21 +00:00
|
|
|
|
|
|
|
+#ifdef HAVE_GETUID
|
|
|
|
+ if (from_tty == -1)
|
|
|
|
+ {
|
|
|
|
+ struct stat statbuf;
|
2008-12-14 14:05:20 +00:00
|
|
|
+
|
2005-06-10 20:50:21 +00:00
|
|
|
+ if (fstat (fd, &statbuf) < 0)
|
|
|
|
+ {
|
2010-07-21 21:30:20 +00:00
|
|
|
+ int save_errno = errno;
|
|
|
|
+
|
2006-07-11 06:33:02 +00:00
|
|
|
+ close (fd);
|
2010-07-21 21:30:20 +00:00
|
|
|
+ do_cleanups (old_cleanups);
|
|
|
|
+ errno = save_errno;
|
|
|
|
+ return 0;
|
2005-06-10 20:50:21 +00:00
|
|
|
+ }
|
|
|
|
+ if (statbuf.st_uid != getuid () || (statbuf.st_mode & S_IWOTH))
|
|
|
|
+ {
|
2008-12-14 14:05:20 +00:00
|
|
|
+ /* FILE gets freed by do_cleanups (old_cleanups). */
|
|
|
|
+ warning (_("not using untrusted file \"%s\""), file);
|
2006-07-11 06:33:02 +00:00
|
|
|
+ close (fd);
|
2008-12-14 14:05:20 +00:00
|
|
|
+ do_cleanups (old_cleanups);
|
2010-07-21 21:30:20 +00:00
|
|
|
+ errno = EPERM;
|
2010-01-21 16:09:11 +00:00
|
|
|
+ return 0;
|
2005-06-10 20:50:21 +00:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+#endif
|
|
|
|
+
|
2010-07-21 21:30:20 +00:00
|
|
|
do_cleanups (old_cleanups);
|
|
|
|
|
|
|
|
*streamp = fdopen (fd, FOPEN_RT);
|
2012-01-03 15:00:12 +00:00
|
|
|
@@ -572,13 +599,14 @@ source_script_with_search (const char *f
|
2010-07-21 21:30:20 +00:00
|
|
|
if (file == NULL || *file == 0)
|
|
|
|
error (_("source command requires file name of file to source."));
|
2010-01-21 16:09:11 +00:00
|
|
|
|
2010-07-21 21:30:20 +00:00
|
|
|
- if (!find_and_open_script (file, search_path, &stream, &full_path))
|
|
|
|
+ if (!find_and_open_script (file, search_path, &stream, &full_path,
|
|
|
|
+ from_tty))
|
2010-01-21 16:09:11 +00:00
|
|
|
{
|
2012-01-03 15:00:12 +00:00
|
|
|
/* The script wasn't found, or was otherwise inaccessible.
|
2011-01-01 00:27:30 +00:00
|
|
|
If the source command was invoked interactively, throw an
|
|
|
|
error. Otherwise (e.g. if it was invoked by a script),
|
|
|
|
silently ignore the error. */
|
2010-01-21 16:09:11 +00:00
|
|
|
- if (from_tty)
|
|
|
|
+ if (from_tty > 0)
|
|
|
|
perror_with_name (file);
|
|
|
|
else
|
2010-07-21 21:30:20 +00:00
|
|
|
return;
|
2012-01-03 15:00:12 +00:00
|
|
|
Index: gdb-7.4.50.20111218/gdb/testsuite/gdb.base/gdbinit.exp
|
2006-07-11 06:33:02 +00:00
|
|
|
===================================================================
|
2008-12-14 14:05:20 +00:00
|
|
|
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
|
2012-01-03 15:00:12 +00:00
|
|
|
+++ gdb-7.4.50.20111218/gdb/testsuite/gdb.base/gdbinit.exp 2011-12-19 00:25:26.079891954 +0100
|
2010-07-21 21:30:20 +00:00
|
|
|
@@ -0,0 +1,91 @@
|
2005-06-10 20:50:21 +00:00
|
|
|
+# Copyright 2005
|
|
|
|
+# 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
|
|
|
|
+# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
+# (at your option) any later version.
|
|
|
|
+#
|
|
|
|
+# This program is distributed in the hope that it will be useful,
|
|
|
|
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
+# GNU General Public License for more details.
|
|
|
|
+#
|
|
|
|
+# You should have received a copy of the GNU General Public License
|
|
|
|
+# along with this program; if not, write to the Free Software
|
2008-12-14 14:05:20 +00:00
|
|
|
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
2005-06-10 20:50:21 +00:00
|
|
|
+
|
|
|
|
+# Please email any bugs, comments, and/or additions to this file to:
|
|
|
|
+# bug-gdb@prep.ai.mit.edu
|
|
|
|
+
|
|
|
|
+# This file was written by Jeff Johnston <jjohnstn@redhat.com>.
|
|
|
|
+
|
|
|
|
+# are we on a target board
|
|
|
|
+if [is_remote target] {
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+global verbose
|
|
|
|
+global GDB
|
|
|
|
+global GDBFLAGS
|
|
|
|
+global gdb_prompt
|
|
|
|
+global timeout
|
|
|
|
+global gdb_spawn_id;
|
2008-12-14 14:05:20 +00:00
|
|
|
+
|
2005-06-10 20:50:21 +00:00
|
|
|
+gdb_stop_suppressing_tests;
|
2008-12-14 14:05:20 +00:00
|
|
|
+
|
2005-06-10 20:50:21 +00:00
|
|
|
+verbose "Spawning $GDB -nw"
|
2008-12-14 14:05:20 +00:00
|
|
|
+
|
2005-06-10 20:50:21 +00:00
|
|
|
+if [info exists gdb_spawn_id] {
|
|
|
|
+ return 0;
|
|
|
|
+}
|
2008-12-14 14:05:20 +00:00
|
|
|
+
|
2005-06-10 20:50:21 +00:00
|
|
|
+if ![is_remote host] {
|
|
|
|
+ if { [which $GDB] == 0 } then {
|
|
|
|
+ perror "$GDB does not exist."
|
|
|
|
+ exit 1
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+set env(HOME) [pwd]
|
|
|
|
+remote_exec build "rm .gdbinit"
|
|
|
|
+remote_exec build "cp ${srcdir}/${subdir}/gdbinit.sample .gdbinit"
|
|
|
|
+remote_exec build "chmod 646 .gdbinit"
|
|
|
|
+
|
|
|
|
+set res [remote_spawn host "$GDB -nw [host_info gdb_opts]"];
|
|
|
|
+if { $res < 0 || $res == "" } {
|
|
|
|
+ perror "Spawning $GDB failed."
|
|
|
|
+ return 1;
|
|
|
|
+}
|
|
|
|
+gdb_expect 360 {
|
|
|
|
+ -re "warning: not using untrusted file.*\.gdbinit.*\[\r\n\]$gdb_prompt $" {
|
|
|
|
+ pass "untrusted .gdbinit caught."
|
|
|
|
+ }
|
|
|
|
+ -re "$gdb_prompt $" {
|
|
|
|
+ fail "untrusted .gdbinit caught."
|
|
|
|
+ }
|
|
|
|
+ timeout {
|
|
|
|
+ fail "(timeout) untrusted .gdbinit caught."
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+remote_exec build "chmod 644 .gdbinit"
|
|
|
|
+set res [remote_spawn host "$GDB -nw [host_info gdb_opts]"];
|
|
|
|
+if { $res < 0 || $res == "" } {
|
|
|
|
+ perror "Spawning $GDB failed."
|
|
|
|
+ return 1;
|
|
|
|
+}
|
|
|
|
+gdb_expect 360 {
|
|
|
|
+ -re "warning: not using untrusted file.*\.gdbinit.*\[\r\n\]$gdb_prompt $" {
|
|
|
|
+ fail "trusted .gdbinit allowed."
|
|
|
|
+ }
|
|
|
|
+ -re "in gdbinit.*$gdb_prompt $" {
|
|
|
|
+ pass "trusted .gdbinit allowed."
|
|
|
|
+ }
|
|
|
|
+ timeout {
|
|
|
|
+ fail "(timeout) trusted .gdbinit allowed."
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+remote_exec build "rm .gdbinit"
|
2012-01-03 15:00:12 +00:00
|
|
|
Index: gdb-7.4.50.20111218/gdb/testsuite/gdb.base/gdbinit.sample
|
2006-07-11 06:33:02 +00:00
|
|
|
===================================================================
|
2008-12-14 14:05:20 +00:00
|
|
|
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
|
2012-01-03 15:00:12 +00:00
|
|
|
+++ gdb-7.4.50.20111218/gdb/testsuite/gdb.base/gdbinit.sample 2011-12-19 00:25:26.079891954 +0100
|
2005-06-10 20:50:21 +00:00
|
|
|
@@ -0,0 +1 @@
|
|
|
|
+echo "\nin gdbinit"
|
2012-01-03 15:00:12 +00:00
|
|
|
Index: gdb-7.4.50.20111218/gdb/main.c
|
2006-07-11 06:33:02 +00:00
|
|
|
===================================================================
|
2012-01-03 15:00:12 +00:00
|
|
|
--- gdb-7.4.50.20111218.orig/gdb/main.c 2011-11-05 18:08:30.000000000 +0100
|
|
|
|
+++ gdb-7.4.50.20111218/gdb/main.c 2011-12-19 00:25:26.080891950 +0100
|
|
|
|
@@ -822,7 +822,7 @@ captured_main (void *data)
|
2009-02-11 00:04:48 +00:00
|
|
|
debugging or what directory you are in. */
|
2005-07-08 18:42:25 +00:00
|
|
|
|
2009-02-11 00:04:48 +00:00
|
|
|
if (home_gdbinit && !inhibit_gdbinit)
|
|
|
|
- catch_command_errors (source_script, home_gdbinit, 0, RETURN_MASK_ALL);
|
|
|
|
+ catch_command_errors (source_script, home_gdbinit, -1, RETURN_MASK_ALL);
|
2005-07-08 18:42:25 +00:00
|
|
|
|
2009-02-11 00:04:48 +00:00
|
|
|
/* Now perform all the actions indicated by the arguments. */
|
|
|
|
if (cdarg != NULL)
|
2012-01-03 15:00:12 +00:00
|
|
|
@@ -901,7 +901,7 @@ captured_main (void *data)
|
2009-02-11 00:04:48 +00:00
|
|
|
/* Read the .gdbinit file in the current directory, *if* it isn't
|
|
|
|
the same as the $HOME/.gdbinit file (it should exist, also). */
|
|
|
|
if (local_gdbinit && !inhibit_gdbinit)
|
|
|
|
- catch_command_errors (source_script, local_gdbinit, 0, RETURN_MASK_ALL);
|
|
|
|
+ catch_command_errors (source_script, local_gdbinit, -1, RETURN_MASK_ALL);
|
2005-07-08 18:42:25 +00:00
|
|
|
|
2010-07-21 21:30:20 +00:00
|
|
|
/* Now that all .gdbinit's have been read and all -d options have been
|
|
|
|
processed, we can read any scripts mentioned in SYMARG.
|
2012-01-03 15:00:12 +00:00
|
|
|
Index: gdb-7.4.50.20111218/gdb/python/py-auto-load.c
|
2010-07-21 21:30:20 +00:00
|
|
|
===================================================================
|
2012-01-03 15:00:12 +00:00
|
|
|
--- gdb-7.4.50.20111218.orig/gdb/python/py-auto-load.c 2011-12-10 23:51:47.000000000 +0100
|
|
|
|
+++ gdb-7.4.50.20111218/gdb/python/py-auto-load.c 2011-12-19 00:25:26.080891950 +0100
|
2011-07-22 22:41:56 +00:00
|
|
|
@@ -284,7 +284,7 @@ source_section_scripts (struct objfile *
|
2010-07-21 21:30:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
opened = find_and_open_script (file, 1 /*search_path*/,
|
|
|
|
- &stream, &full_path);
|
|
|
|
+ &stream, &full_path, 1 /* from_tty */);
|
|
|
|
|
2011-07-22 22:41:56 +00:00
|
|
|
/* If one script isn't found it's not uncommon for more to not be
|
|
|
|
found either. We don't want to print an error message for each
|
2012-01-03 15:00:12 +00:00
|
|
|
Index: gdb-7.4.50.20111218/gdb/cli/cli-cmds.h
|
2010-07-21 21:30:20 +00:00
|
|
|
===================================================================
|
2012-01-03 15:00:12 +00:00
|
|
|
--- gdb-7.4.50.20111218.orig/gdb/cli/cli-cmds.h 2011-11-01 15:51:23.000000000 +0100
|
|
|
|
+++ gdb-7.4.50.20111218/gdb/cli/cli-cmds.h 2011-12-19 00:25:26.080891950 +0100
|
|
|
|
@@ -129,7 +129,8 @@ extern void source_script (char *, int);
|
2010-07-21 21:30:20 +00:00
|
|
|
/* Exported to objfiles.c. */
|
|
|
|
|
|
|
|
extern int find_and_open_script (const char *file, int search_path,
|
|
|
|
- FILE **streamp, char **full_path);
|
|
|
|
+ FILE **streamp, char **full_path,
|
|
|
|
+ int from_tty);
|
|
|
|
|
|
|
|
/* Command tracing state. */
|
|
|
|
|