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
aefb0e1
Index: gdb-6.6/gdb/cli/cli-cmds.c
9231e41
===================================================================
aefb0e1
--- gdb-6.6.orig/gdb/cli/cli-cmds.c
aefb0e1
+++ gdb-6.6/gdb/cli/cli-cmds.c
d939943
@@ -38,6 +38,7 @@
d939943
 #include "objfiles.h"
d939943
 #include "source.h"
d939943
 #include "disasm.h"
d939943
+#include "gdb_stat.h"
d939943
 
d939943
 #include "ui-out.h"
d939943
 
aefb0e1
@@ -461,12 +462,31 @@ source_script (char *file, int from_tty)
d939943
 
9231e41
   if (fd == -1)
d939943
     {
d939943
-      if (from_tty)
d939943
+      if (from_tty > 0)
d939943
 	perror_with_name (file);
d939943
       else
d939943
 	return;
d939943
     }
d939943
 
d939943
+#ifdef HAVE_GETUID
d939943
+  if (from_tty == -1)
d939943
+    {
d939943
+      struct stat statbuf;
d939943
+      if (fstat (fd, &statbuf) < 0)
d939943
+	{
d939943
+	  perror_with_name (file);
9231e41
+	  close (fd);
d939943
+	  return;
d939943
+	}
d939943
+      if (statbuf.st_uid != getuid () || (statbuf.st_mode & S_IWOTH))
d939943
+	{
d939943
+          warning (_("not using untrusted file \"%s\""), file);
9231e41
+	  close (fd);
d939943
+	  return;
d939943
+	}
d939943
+    }
d939943
+#endif
d939943
+
9231e41
   stream = fdopen (fd, FOPEN_RT);
d939943
   script_from_file (stream, file);
d939943
 
aefb0e1
Index: gdb-6.6/gdb/testsuite/gdb.base/gdbinit.exp
9231e41
===================================================================
aefb0e1
--- /dev/null
aefb0e1
+++ gdb-6.6/gdb/testsuite/gdb.base/gdbinit.exp
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
d939943
+# 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;
d939943
+                                                                                
d939943
+gdb_stop_suppressing_tests;
d939943
+                                                                                
d939943
+verbose "Spawning $GDB -nw"
d939943
+                                                                                
d939943
+if [info exists gdb_spawn_id] {
d939943
+    return 0;
d939943
+}
d939943
+                                                                                
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"
aefb0e1
Index: gdb-6.6/gdb/testsuite/gdb.base/gdbinit.sample
9231e41
===================================================================
aefb0e1
--- /dev/null
aefb0e1
+++ gdb-6.6/gdb/testsuite/gdb.base/gdbinit.sample
d939943
@@ -0,0 +1 @@
d939943
+echo "\nin gdbinit"
aefb0e1
Index: gdb-6.6/gdb/main.c
9231e41
===================================================================
aefb0e1
--- gdb-6.6.orig/gdb/main.c
aefb0e1
+++ gdb-6.6/gdb/main.c
aefb0e1
@@ -644,7 +644,7 @@ extern int gdbtk_test (char *);
adbc6b8
 
adbc6b8
       if (!inhibit_gdbinit)
adbc6b8
 	{
aefb0e1
-	  catch_command_errors (source_script, homeinit, 0, RETURN_MASK_ALL);
aefb0e1
+	  catch_command_errors (source_script, homeinit, -1, RETURN_MASK_ALL);
adbc6b8
 	}
adbc6b8
 
adbc6b8
       /* Do stats; no need to do them elsewhere since we'll only
aefb0e1
@@ -722,7 +722,7 @@ extern int gdbtk_test (char *);
adbc6b8
       || memcmp ((char *) &homebuf, (char *) &cwdbuf, sizeof (struct stat)))
adbc6b8
     if (!inhibit_gdbinit)
adbc6b8
       {
aefb0e1
-	catch_command_errors (source_script, gdbinit, 0, RETURN_MASK_ALL);
aefb0e1
+	catch_command_errors (source_script, gdbinit, -1, RETURN_MASK_ALL);
adbc6b8
       }
adbc6b8
 
adbc6b8
   for (i = 0; i < ncmd; i++)
aefb0e1
Index: gdb-6.6/gdb/Makefile.in
9231e41
===================================================================
aefb0e1
--- gdb-6.6.orig/gdb/Makefile.in
aefb0e1
+++ gdb-6.6/gdb/Makefile.in
aefb0e1
@@ -2927,7 +2927,7 @@ cli-cmds.o: $(srcdir)/cli/cli-cmds.c $(d
adbc6b8
 	$(expression_h) $(frame_h) $(value_h) $(language_h) $(filenames_h) \
adbc6b8
 	$(objfiles_h) $(source_h) $(disasm_h) $(ui_out_h) $(top_h) \
adbc6b8
 	$(cli_decode_h) $(cli_script_h) $(cli_setshow_h) $(cli_cmds_h) \
adbc6b8
-	$(tui_h)
adbc6b8
+	$(tui_h) $(gdb_stat_h)
adbc6b8
 	$(CC) -c $(INTERNAL_CFLAGS) $(srcdir)/cli/cli-cmds.c
adbc6b8
 cli-decode.o: $(srcdir)/cli/cli-decode.c $(defs_h) $(symtab_h) \
9231e41
 	$(gdb_regex_h) $(gdb_string_h) $(completer_h) $(ui_out_h) \