patches/gdb/6.7.1/100-security-errata-20050610.patch
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Mon Jul 28 21:32:33 2008 +0000 (2008-07-28)
changeset 747 d3e603e7c17c
parent 746 patches/gdb/6.7.1/150-security-errata-20050610.patch@b150d6f590fc
permissions -rw-r--r--
Fourth step at renaming patches: renumber all patches with a 10-step.
     1 Original patch from gentoo: gentoo/src/patchsets/gdb/6.7.1/35_all_gdb-6.3-security-errata-20050610.patch
     2 -= BEGIN original header =-
     3 2005-06-09  Jeff Johnston  <jjohnstn@redhat.com>
     4 
     5         * gdb.base/gdbinit.exp: New testcase.
     6         * gdb.base/gdbinit.sample: Sample .gdbinit for gdbinit.exp.
     7 
     8 2005-06-08  Daniel Jacobowitz  <dan@codesourcery.com>
     9             Jeff Johnston  <jjohnstn@redhat.com>
    10 
    11         * Makefile.in (cli-cmds.o): Update.
    12         * configure.in: Add check for getuid.
    13         * configure: Regenerated.
    14         * config.in: Ditto.
    15         * main.c (captured_main): Pass -1 to source_command when loading
    16         gdbinit files.
    17         * cli/cli-cmds.c: Include "gdb_stat.h" and <fcntl.h>.
    18         (source_command): Update documentation.  Check permissions if
    19         FROM_TTY is -1.
    20 
    21 -= END original header =-
    22 diff -durN gdb-6.7.1.orig/gdb/cli/cli-cmds.c gdb-6.7.1/gdb/cli/cli-cmds.c
    23 --- gdb-6.7.1.orig/gdb/cli/cli-cmds.c	2007-08-23 20:08:47.000000000 +0200
    24 +++ gdb-6.7.1/gdb/cli/cli-cmds.c	2008-06-17 23:27:44.000000000 +0200
    25 @@ -36,6 +36,7 @@
    26  #include "objfiles.h"
    27  #include "source.h"
    28  #include "disasm.h"
    29 +#include "gdb_stat.h"
    30  
    31  #include "ui-out.h"
    32  
    33 @@ -459,12 +460,31 @@
    34  
    35    if (fd == -1)
    36      {
    37 -      if (from_tty)
    38 +      if (from_tty > 0)
    39  	perror_with_name (file);
    40        else
    41  	return;
    42      }
    43  
    44 +#ifdef HAVE_GETUID
    45 +  if (from_tty == -1)
    46 +    {
    47 +      struct stat statbuf;
    48 +      if (fstat (fd, &statbuf) < 0)
    49 +	{
    50 +	  perror_with_name (file);
    51 +	  close (fd);
    52 +	  return;
    53 +	}
    54 +      if (statbuf.st_uid != getuid () || (statbuf.st_mode & S_IWOTH))
    55 +	{
    56 +          warning (_("not using untrusted file \"%s\""), file);
    57 +	  close (fd);
    58 +	  return;
    59 +	}
    60 +    }
    61 +#endif
    62 +
    63    stream = fdopen (fd, FOPEN_RT);
    64    script_from_file (stream, file);
    65  
    66 diff -durN gdb-6.7.1.orig/gdb/main.c gdb-6.7.1/gdb/main.c
    67 --- gdb-6.7.1.orig/gdb/main.c	2007-08-23 20:08:36.000000000 +0200
    68 +++ gdb-6.7.1/gdb/main.c	2008-06-17 23:27:44.000000000 +0200
    69 @@ -688,7 +688,7 @@
    70  
    71        if (!inhibit_gdbinit)
    72  	{
    73 -	  catch_command_errors (source_script, homeinit, 0, RETURN_MASK_ALL);
    74 +	  catch_command_errors (source_script, homeinit, -1, RETURN_MASK_ALL);
    75  	}
    76  
    77        /* Do stats; no need to do them elsewhere since we'll only
    78 @@ -766,7 +766,7 @@
    79        || memcmp ((char *) &homebuf, (char *) &cwdbuf, sizeof (struct stat)))
    80      if (!inhibit_gdbinit)
    81        {
    82 -	catch_command_errors (source_script, gdbinit, 0, RETURN_MASK_ALL);
    83 +	catch_command_errors (source_script, gdbinit, -1, RETURN_MASK_ALL);
    84        }
    85  
    86    for (i = 0; i < ncmd; i++)
    87 diff -durN gdb-6.7.1.orig/gdb/Makefile.in gdb-6.7.1/gdb/Makefile.in
    88 --- gdb-6.7.1.orig/gdb/Makefile.in	2008-06-17 23:27:44.000000000 +0200
    89 +++ gdb-6.7.1/gdb/Makefile.in	2008-06-17 23:27:44.000000000 +0200
    90 @@ -2885,7 +2885,7 @@
    91  	$(expression_h) $(frame_h) $(value_h) $(language_h) $(filenames_h) \
    92  	$(objfiles_h) $(source_h) $(disasm_h) $(ui_out_h) $(top_h) \
    93  	$(cli_decode_h) $(cli_script_h) $(cli_setshow_h) $(cli_cmds_h) \
    94 -	$(tui_h)
    95 +	$(tui_h) $(gdb_stat_h)
    96  	$(CC) -c $(INTERNAL_CFLAGS) $(srcdir)/cli/cli-cmds.c
    97  cli-decode.o: $(srcdir)/cli/cli-decode.c $(defs_h) $(symtab_h) \
    98  	$(gdb_regex_h) $(gdb_string_h) $(completer_h) $(ui_out_h) \
    99 diff -durN gdb-6.7.1.orig/gdb/testsuite/gdb.base/gdbinit.exp gdb-6.7.1/gdb/testsuite/gdb.base/gdbinit.exp
   100 --- gdb-6.7.1.orig/gdb/testsuite/gdb.base/gdbinit.exp	1970-01-01 01:00:00.000000000 +0100
   101 +++ gdb-6.7.1/gdb/testsuite/gdb.base/gdbinit.exp	2008-06-17 23:27:44.000000000 +0200
   102 @@ -0,0 +1,98 @@
   103 +#   Copyright 2005
   104 +#   Free Software Foundation, Inc.
   105 +
   106 +# This program is free software; you can redistribute it and/or modify
   107 +# it under the terms of the GNU General Public License as published by
   108 +# the Free Software Foundation; either version 2 of the License, or
   109 +# (at your option) any later version.
   110 +# 
   111 +# This program is distributed in the hope that it will be useful,
   112 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
   113 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   114 +# GNU General Public License for more details.
   115 +# 
   116 +# You should have received a copy of the GNU General Public License
   117 +# along with this program; if not, write to the Free Software
   118 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
   119 +
   120 +# Please email any bugs, comments, and/or additions to this file to:
   121 +# bug-gdb@prep.ai.mit.edu
   122 +
   123 +# This file was written by Jeff Johnston <jjohnstn@redhat.com>.
   124 +
   125 +if $tracelevel then {
   126 +    strace $tracelevel
   127 +}
   128 +
   129 +set prms_id 0
   130 +set bug_id 0
   131 +
   132 +# are we on a target board
   133 +if [is_remote target] {
   134 +    return
   135 +}
   136 +
   137 +
   138 +global verbose
   139 +global GDB
   140 +global GDBFLAGS
   141 +global gdb_prompt
   142 +global timeout
   143 +global gdb_spawn_id;
   144 +                                                                                
   145 +gdb_stop_suppressing_tests;
   146 +                                                                                
   147 +verbose "Spawning $GDB -nw"
   148 +                                                                                
   149 +if [info exists gdb_spawn_id] {
   150 +    return 0;
   151 +}
   152 +                                                                                
   153 +if ![is_remote host] {
   154 +   if { [which $GDB] == 0 } then {
   155 +        perror "$GDB does not exist."
   156 +        exit 1
   157 +    }
   158 +}
   159 +
   160 +set env(HOME) [pwd]
   161 +remote_exec build "rm .gdbinit"
   162 +remote_exec build "cp ${srcdir}/${subdir}/gdbinit.sample .gdbinit"
   163 +remote_exec build "chmod 646 .gdbinit"
   164 +
   165 +set res [remote_spawn host "$GDB -nw [host_info gdb_opts]"];
   166 +if { $res < 0 || $res == "" } {
   167 +    perror "Spawning $GDB failed."
   168 +    return 1;
   169 +}
   170 +gdb_expect 360 {
   171 +    -re "warning: not using untrusted file.*\.gdbinit.*\[\r\n\]$gdb_prompt $" {
   172 +        pass "untrusted .gdbinit caught."
   173 +    }
   174 +    -re "$gdb_prompt $"     {
   175 +        fail "untrusted .gdbinit caught."
   176 +    }
   177 +    timeout {
   178 +        fail "(timeout) untrusted .gdbinit caught."
   179 +    }
   180 +}
   181 +
   182 +remote_exec build "chmod 644 .gdbinit"
   183 +set res [remote_spawn host "$GDB -nw [host_info gdb_opts]"];
   184 +if { $res < 0 || $res == "" } {
   185 +    perror "Spawning $GDB failed."
   186 +    return 1;
   187 +}
   188 +gdb_expect 360 {
   189 +    -re "warning: not using untrusted file.*\.gdbinit.*\[\r\n\]$gdb_prompt $" {
   190 +        fail "trusted .gdbinit allowed."
   191 +    }
   192 +    -re "in gdbinit.*$gdb_prompt $"     {
   193 +        pass "trusted .gdbinit allowed."
   194 +    }
   195 +    timeout {
   196 +        fail "(timeout) trusted .gdbinit allowed."
   197 +    }
   198 +}
   199 +
   200 +remote_exec build "rm .gdbinit"
   201 diff -durN gdb-6.7.1.orig/gdb/testsuite/gdb.base/gdbinit.sample gdb-6.7.1/gdb/testsuite/gdb.base/gdbinit.sample
   202 --- gdb-6.7.1.orig/gdb/testsuite/gdb.base/gdbinit.sample	1970-01-01 01:00:00.000000000 +0100
   203 +++ gdb-6.7.1/gdb/testsuite/gdb.base/gdbinit.sample	2008-06-17 23:27:44.000000000 +0200
   204 @@ -0,0 +1 @@
   205 +echo "\nin gdbinit"