|
|
407ebe9 |
http://sourceware.org/ml/gdb-patches/2005-05/threads.html#00637
|
|
|
407ebe9 |
Proposed upstream but never committed upstream.
|
|
|
407ebe9 |
|
|
|
d939943 |
2005-06-09 Jeff Johnston <jjohnstn@redhat.com>
|
|
|
d939943 |
|
|
|
d939943 |
* gdb.base/gdbinit.exp: New testcase.
|
|
|
d939943 |
* gdb.base/gdbinit.sample: Sample .gdbinit for gdbinit.exp.
|
|
|
d939943 |
|
|
|
d939943 |
2005-06-08 Daniel Jacobowitz <dan@codesourcery.com>
|
|
|
d939943 |
Jeff Johnston <jjohnstn@redhat.com>
|
|
|
d939943 |
|
|
|
d939943 |
* Makefile.in (cli-cmds.o): Update.
|
|
|
d939943 |
* configure.in: Add check for getuid.
|
|
|
d939943 |
* configure: Regenerated.
|
|
|
d939943 |
* config.in: Ditto.
|
|
|
d939943 |
* main.c (captured_main): Pass -1 to source_command when loading
|
|
|
d939943 |
gdbinit files.
|
|
|
d939943 |
* cli/cli-cmds.c: Include "gdb_stat.h" and <fcntl.h>.
|
|
|
d939943 |
(source_command): Update documentation. Check permissions if
|
|
|
d939943 |
FROM_TTY is -1.
|
|
|
d939943 |
|
|
|
79563d6 |
Index: gdb-7.0.50.20100121/gdb/cli/cli-cmds.c
|
|
|
9231e41 |
===================================================================
|
|
|
79563d6 |
--- gdb-7.0.50.20100121.orig/gdb/cli/cli-cmds.c 2010-01-18 07:25:22.000000000 +0100
|
|
|
79563d6 |
+++ gdb-7.0.50.20100121/gdb/cli/cli-cmds.c 2010-01-21 15:12:28.000000000 +0100
|
|
|
79563d6 |
@@ -38,6 +38,7 @@
|
|
|
d939943 |
#include "objfiles.h"
|
|
|
d939943 |
#include "source.h"
|
|
|
d939943 |
#include "disasm.h"
|
|
|
d939943 |
+#include "gdb_stat.h"
|
|
|
8c4c91e |
extern void disconnect_or_stop_tracing (int from_tty);
|
|
|
d939943 |
|
|
|
d939943 |
#include "ui-out.h"
|
|
|
79563d6 |
@@ -488,6 +489,29 @@ find_and_open_script (int from_tty, char
|
|
|
79563d6 |
file, O_RDONLY, &full_pathname);
|
|
|
79563d6 |
make_cleanup (xfree, full_pathname);
|
|
|
d939943 |
|
|
|
d939943 |
+#ifdef HAVE_GETUID
|
|
|
d939943 |
+ if (from_tty == -1)
|
|
|
d939943 |
+ {
|
|
|
d939943 |
+ struct stat statbuf;
|
|
|
407ebe9 |
+
|
|
|
d939943 |
+ if (fstat (fd, &statbuf) < 0)
|
|
|
d939943 |
+ {
|
|
|
9231e41 |
+ close (fd);
|
|
|
407ebe9 |
+ /* Do not do_cleanups (old_cleanups) as FILE is allocated there.
|
|
|
407ebe9 |
+ perror_with_name calls error which should call the cleanups. */
|
|
|
407ebe9 |
+ perror_with_name (file);
|
|
|
d939943 |
+ }
|
|
|
d939943 |
+ if (statbuf.st_uid != getuid () || (statbuf.st_mode & S_IWOTH))
|
|
|
d939943 |
+ {
|
|
|
407ebe9 |
+ /* FILE gets freed by do_cleanups (old_cleanups). */
|
|
|
407ebe9 |
+ warning (_("not using untrusted file \"%s\""), file);
|
|
|
9231e41 |
+ close (fd);
|
|
|
407ebe9 |
+ do_cleanups (old_cleanups);
|
|
|
79563d6 |
+ return 0;
|
|
|
d939943 |
+ }
|
|
|
d939943 |
+ }
|
|
|
d939943 |
+#endif
|
|
|
d939943 |
+
|
|
|
79563d6 |
/* Use the full path name, if it is found. */
|
|
|
79563d6 |
if (full_pathname != NULL && fd != -1)
|
|
|
79563d6 |
{
|
|
|
79563d6 |
@@ -496,7 +520,7 @@ find_and_open_script (int from_tty, char
|
|
|
79563d6 |
|
|
|
79563d6 |
if (fd == -1)
|
|
|
79563d6 |
{
|
|
|
79563d6 |
- if (from_tty)
|
|
|
79563d6 |
+ if (from_tty > 0)
|
|
|
79563d6 |
perror_with_name (file);
|
|
|
79563d6 |
else
|
|
|
79563d6 |
{
|
|
|
79563d6 |
@@ -554,6 +578,7 @@ source_script (char *file, int from_tty)
|
|
|
1592379 |
else
|
|
|
1592379 |
script_from_file (stream, file);
|
|
|
d939943 |
|
|
|
407ebe9 |
+ /* FILE gets freed by do_cleanups (old_cleanups). */
|
|
|
407ebe9 |
do_cleanups (old_cleanups);
|
|
|
407ebe9 |
}
|
|
|
407ebe9 |
|
|
|
79563d6 |
Index: gdb-7.0.50.20100121/gdb/testsuite/gdb.base/gdbinit.exp
|
|
|
9231e41 |
===================================================================
|
|
|
407ebe9 |
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
|
|
|
79563d6 |
+++ gdb-7.0.50.20100121/gdb/testsuite/gdb.base/gdbinit.exp 2010-01-21 15:11:18.000000000 +0100
|
|
|
d939943 |
@@ -0,0 +1,98 @@
|
|
|
d939943 |
+# Copyright 2005
|
|
|
d939943 |
+# Free Software Foundation, Inc.
|
|
|
d939943 |
+
|
|
|
d939943 |
+# This program is free software; you can redistribute it and/or modify
|
|
|
d939943 |
+# it under the terms of the GNU General Public License as published by
|
|
|
d939943 |
+# the Free Software Foundation; either version 2 of the License, or
|
|
|
d939943 |
+# (at your option) any later version.
|
|
|
d939943 |
+#
|
|
|
d939943 |
+# This program is distributed in the hope that it will be useful,
|
|
|
d939943 |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
d939943 |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
d939943 |
+# GNU General Public License for more details.
|
|
|
d939943 |
+#
|
|
|
d939943 |
+# You should have received a copy of the GNU General Public License
|
|
|
d939943 |
+# along with this program; if not, write to the Free Software
|
|
|
407ebe9 |
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
d939943 |
+
|
|
|
d939943 |
+# Please email any bugs, comments, and/or additions to this file to:
|
|
|
d939943 |
+# bug-gdb@prep.ai.mit.edu
|
|
|
d939943 |
+
|
|
|
d939943 |
+# This file was written by Jeff Johnston <jjohnstn@redhat.com>.
|
|
|
d939943 |
+
|
|
|
d939943 |
+if $tracelevel then {
|
|
|
d939943 |
+ strace $tracelevel
|
|
|
d939943 |
+}
|
|
|
d939943 |
+
|
|
|
d939943 |
+set prms_id 0
|
|
|
d939943 |
+set bug_id 0
|
|
|
d939943 |
+
|
|
|
d939943 |
+# are we on a target board
|
|
|
d939943 |
+if [is_remote target] {
|
|
|
d939943 |
+ return
|
|
|
d939943 |
+}
|
|
|
d939943 |
+
|
|
|
d939943 |
+
|
|
|
d939943 |
+global verbose
|
|
|
d939943 |
+global GDB
|
|
|
d939943 |
+global GDBFLAGS
|
|
|
d939943 |
+global gdb_prompt
|
|
|
d939943 |
+global timeout
|
|
|
d939943 |
+global gdb_spawn_id;
|
|
|
407ebe9 |
+
|
|
|
d939943 |
+gdb_stop_suppressing_tests;
|
|
|
407ebe9 |
+
|
|
|
d939943 |
+verbose "Spawning $GDB -nw"
|
|
|
407ebe9 |
+
|
|
|
d939943 |
+if [info exists gdb_spawn_id] {
|
|
|
d939943 |
+ return 0;
|
|
|
d939943 |
+}
|
|
|
407ebe9 |
+
|
|
|
d939943 |
+if ![is_remote host] {
|
|
|
d939943 |
+ if { [which $GDB] == 0 } then {
|
|
|
d939943 |
+ perror "$GDB does not exist."
|
|
|
d939943 |
+ exit 1
|
|
|
d939943 |
+ }
|
|
|
d939943 |
+}
|
|
|
d939943 |
+
|
|
|
d939943 |
+set env(HOME) [pwd]
|
|
|
d939943 |
+remote_exec build "rm .gdbinit"
|
|
|
d939943 |
+remote_exec build "cp ${srcdir}/${subdir}/gdbinit.sample .gdbinit"
|
|
|
d939943 |
+remote_exec build "chmod 646 .gdbinit"
|
|
|
d939943 |
+
|
|
|
d939943 |
+set res [remote_spawn host "$GDB -nw [host_info gdb_opts]"];
|
|
|
d939943 |
+if { $res < 0 || $res == "" } {
|
|
|
d939943 |
+ perror "Spawning $GDB failed."
|
|
|
d939943 |
+ return 1;
|
|
|
d939943 |
+}
|
|
|
d939943 |
+gdb_expect 360 {
|
|
|
d939943 |
+ -re "warning: not using untrusted file.*\.gdbinit.*\[\r\n\]$gdb_prompt $" {
|
|
|
d939943 |
+ pass "untrusted .gdbinit caught."
|
|
|
d939943 |
+ }
|
|
|
d939943 |
+ -re "$gdb_prompt $" {
|
|
|
d939943 |
+ fail "untrusted .gdbinit caught."
|
|
|
d939943 |
+ }
|
|
|
d939943 |
+ timeout {
|
|
|
d939943 |
+ fail "(timeout) untrusted .gdbinit caught."
|
|
|
d939943 |
+ }
|
|
|
d939943 |
+}
|
|
|
d939943 |
+
|
|
|
d939943 |
+remote_exec build "chmod 644 .gdbinit"
|
|
|
d939943 |
+set res [remote_spawn host "$GDB -nw [host_info gdb_opts]"];
|
|
|
d939943 |
+if { $res < 0 || $res == "" } {
|
|
|
d939943 |
+ perror "Spawning $GDB failed."
|
|
|
d939943 |
+ return 1;
|
|
|
d939943 |
+}
|
|
|
d939943 |
+gdb_expect 360 {
|
|
|
d939943 |
+ -re "warning: not using untrusted file.*\.gdbinit.*\[\r\n\]$gdb_prompt $" {
|
|
|
d939943 |
+ fail "trusted .gdbinit allowed."
|
|
|
d939943 |
+ }
|
|
|
d939943 |
+ -re "in gdbinit.*$gdb_prompt $" {
|
|
|
d939943 |
+ pass "trusted .gdbinit allowed."
|
|
|
d939943 |
+ }
|
|
|
d939943 |
+ timeout {
|
|
|
d939943 |
+ fail "(timeout) trusted .gdbinit allowed."
|
|
|
d939943 |
+ }
|
|
|
d939943 |
+}
|
|
|
d939943 |
+
|
|
|
d939943 |
+remote_exec build "rm .gdbinit"
|
|
|
79563d6 |
Index: gdb-7.0.50.20100121/gdb/testsuite/gdb.base/gdbinit.sample
|
|
|
9231e41 |
===================================================================
|
|
|
407ebe9 |
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
|
|
|
79563d6 |
+++ gdb-7.0.50.20100121/gdb/testsuite/gdb.base/gdbinit.sample 2010-01-21 15:11:18.000000000 +0100
|
|
|
d939943 |
@@ -0,0 +1 @@
|
|
|
d939943 |
+echo "\nin gdbinit"
|
|
|
79563d6 |
Index: gdb-7.0.50.20100121/gdb/main.c
|
|
|
9231e41 |
===================================================================
|
|
|
79563d6 |
--- gdb-7.0.50.20100121.orig/gdb/main.c 2010-01-21 15:11:09.000000000 +0100
|
|
|
79563d6 |
+++ gdb-7.0.50.20100121/gdb/main.c 2010-01-21 15:11:18.000000000 +0100
|
|
|
79563d6 |
@@ -818,7 +818,7 @@ Excess command line arguments ignored. (
|
|
|
81783d0 |
debugging or what directory you are in. */
|
|
|
adbc6b8 |
|
|
|
81783d0 |
if (home_gdbinit && !inhibit_gdbinit)
|
|
|
81783d0 |
- catch_command_errors (source_script, home_gdbinit, 0, RETURN_MASK_ALL);
|
|
|
81783d0 |
+ catch_command_errors (source_script, home_gdbinit, -1, RETURN_MASK_ALL);
|
|
|
adbc6b8 |
|
|
|
81783d0 |
/* Now perform all the actions indicated by the arguments. */
|
|
|
81783d0 |
if (cdarg != NULL)
|
|
|
79563d6 |
@@ -887,7 +887,7 @@ Can't attach to process and specify a co
|
|
|
81783d0 |
/* Read the .gdbinit file in the current directory, *if* it isn't
|
|
|
81783d0 |
the same as the $HOME/.gdbinit file (it should exist, also). */
|
|
|
81783d0 |
if (local_gdbinit && !inhibit_gdbinit)
|
|
|
81783d0 |
- catch_command_errors (source_script, local_gdbinit, 0, RETURN_MASK_ALL);
|
|
|
81783d0 |
+ catch_command_errors (source_script, local_gdbinit, -1, RETURN_MASK_ALL);
|
|
|
adbc6b8 |
|
|
|
adbc6b8 |
for (i = 0; i < ncmd; i++)
|
|
|
81783d0 |
{
|