Blob Blame History Raw
diff -Naur insight-7.4.50.orig/gdb/cli/cli-cmds.c insight-7.4.50.new/gdb/cli/cli-cmds.c
--- insight-7.4.50.orig/gdb/cli/cli-cmds.c	2012-03-01 20:30:21.000000000 +0100
+++ insight-7.4.50.new/gdb/cli/cli-cmds.c	2012-04-04 15:12:04.335397353 +0200
@@ -39,6 +39,7 @@
 #include "source.h"
 #include "disasm.h"
 #include "tracepoint.h"
+#include "gdb_stat.h"
 
 #include "ui-out.h"
 
@@ -484,7 +485,7 @@
 
 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;
@@ -510,6 +511,32 @@
       return 0;
     }
 
+#ifdef HAVE_GETUID
+  if (from_tty == -1)
+    {
+      struct stat statbuf;
+
+      if (fstat (fd, &statbuf) < 0)
+	{
+	  int save_errno = errno;
+
+	  close (fd);
+	  do_cleanups (old_cleanups);
+	  errno = save_errno;
+	  return 0;
+	}
+      if (statbuf.st_uid != getuid () || (statbuf.st_mode & S_IWOTH))
+	{
+	  /* FILE gets freed by do_cleanups (old_cleanups).  */
+	  warning (_("not using untrusted file \"%s\""), file);
+	  close (fd);
+	  do_cleanups (old_cleanups);
+	  errno = EPERM;
+	  return 0;
+	}
+    }
+#endif
+
   do_cleanups (old_cleanups);
 
   *streamp = fdopen (fd, FOPEN_RT);
@@ -576,13 +603,14 @@
   if (file == NULL || *file == 0)
     error (_("source command requires file name of file to source."));
 
-  if (!find_and_open_script (file, search_path, &stream, &full_path))
+  if (!find_and_open_script (file, search_path, &stream, &full_path,
+			     from_tty))
     {
       /* The script wasn't found, or was otherwise inaccessible.
          If the source command was invoked interactively, throw an
 	 error.  Otherwise (e.g. if it was invoked by a script),
 	 silently ignore the error.  */
-      if (from_tty)
+      if (from_tty > 0)
 	perror_with_name (file);
       else
 	return;
diff -Naur insight-7.4.50.orig/gdb/cli/cli-cmds.h insight-7.4.50.new/gdb/cli/cli-cmds.h
--- insight-7.4.50.orig/gdb/cli/cli-cmds.h	2012-01-04 09:17:16.000000000 +0100
+++ insight-7.4.50.new/gdb/cli/cli-cmds.h	2012-04-04 15:12:04.337397302 +0200
@@ -128,7 +128,8 @@
 /* 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.  */
 
diff -Naur insight-7.4.50.orig/gdb/main.c insight-7.4.50.new/gdb/main.c
--- insight-7.4.50.orig/gdb/main.c	2012-03-19 19:19:24.000000000 +0100
+++ insight-7.4.50.new/gdb/main.c	2012-04-04 15:12:04.335397353 +0200
@@ -861,7 +861,7 @@
      debugging or what directory you are in.  */
 
   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);
 
   /* Now perform all the actions indicated by the arguments.  */
   if (cdarg != NULL)
@@ -940,7 +940,7 @@
   /* 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);
 
   /* Now that all .gdbinit's have been read and all -d options have been
      processed, we can read any scripts mentioned in SYMARG.
diff -Naur insight-7.4.50.orig/gdb/python/py-auto-load.c insight-7.4.50.new/gdb/python/py-auto-load.c
--- insight-7.4.50.orig/gdb/python/py-auto-load.c	2012-03-19 19:23:52.000000000 +0100
+++ insight-7.4.50.new/gdb/python/py-auto-load.c	2012-04-04 15:12:04.336397329 +0200
@@ -285,7 +285,7 @@
 	}
 
       opened = find_and_open_script (file, 1 /*search_path*/,
-				     &stream, &full_path);
+				     &stream, &full_path, 1 /* from_tty */);
 
       back_to = make_cleanup (null_cleanup, NULL);
       if (opened)
diff -Naur insight-7.4.50.orig/gdb/testsuite/gdb.base/gdbinit.exp insight-7.4.50.new/gdb/testsuite/gdb.base/gdbinit.exp
--- insight-7.4.50.orig/gdb/testsuite/gdb.base/gdbinit.exp	1970-01-01 01:00:00.000000000 +0100
+++ insight-7.4.50.new/gdb/testsuite/gdb.base/gdbinit.exp	2012-04-04 15:12:04.335397353 +0200
@@ -0,0 +1,91 @@
+#   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
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+# 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;
+
+gdb_stop_suppressing_tests;
+
+verbose "Spawning $GDB -nw"
+
+if [info exists gdb_spawn_id] {
+    return 0;
+}
+
+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"
diff -Naur insight-7.4.50.orig/gdb/testsuite/gdb.base/gdbinit.sample insight-7.4.50.new/gdb/testsuite/gdb.base/gdbinit.sample
--- insight-7.4.50.orig/gdb/testsuite/gdb.base/gdbinit.sample	1970-01-01 01:00:00.000000000 +0100
+++ insight-7.4.50.new/gdb/testsuite/gdb.base/gdbinit.sample	2012-04-04 15:12:04.335397353 +0200
@@ -0,0 +1 @@
+echo "\nin gdbinit"