acb618c
Failing on _FORTIFY_SOURCE=2 for `gdb.base/corefile.exp'.
acb618c
acb618c
acb618c
--- gdb-6.6/gdb/linux-nat.c-orig	2007-04-08 21:12:38.000000000 +0200
acb618c
+++ gdb-6.6/gdb/linux-nat.c	2007-04-09 20:05:43.000000000 +0200
acb618c
@@ -2838,7 +2838,9 @@ linux_nat_make_corefile_notes (bfd *obfd
acb618c
 {
acb618c
   struct linux_nat_corefile_thread_data thread_args;
acb618c
   struct cleanup *old_chain;
acb618c
+  /* Length must be >= sizeof (prpsinfo_t.pr_fname).  */
acb618c
   char fname[16] = { '\0' };
acb618c
+  /* Length must be >= sizeof (prpsinfo_t.pr_psargs).  */
acb618c
   char psargs[80] = { '\0' };
acb618c
   char *note_data = NULL;
acb618c
   ptid_t current_ptid = inferior_ptid;
acb618c
@@ -2851,9 +2853,14 @@ linux_nat_make_corefile_notes (bfd *obfd
acb618c
       strncpy (psargs, get_exec_file (0), sizeof (psargs));
acb618c
       if (get_inferior_args ())
acb618c
 	{
acb618c
-	  strncat (psargs, " ", sizeof (psargs) - strlen (psargs));
acb618c
-	  strncat (psargs, get_inferior_args (),
acb618c
-		   sizeof (psargs) - strlen (psargs));
acb618c
+	  /* linux_elfcore_write_prpsinfo () handles zero non-terminated
acb618c
+	     strings right if they provide enough characters for its purposes.
acb618c
+	     Handle to fully filled (=> zero non-terminated) strings here.  */
acb618c
+	  if (memchr (psargs, 0, sizeof (psargs)) != NULL)
acb618c
+	    strncat (psargs, " ", sizeof (psargs) - strlen (psargs) - 1);
acb618c
+	  if (memchr (psargs, 0, sizeof (psargs)) != NULL)
acb618c
+	    strncat (psargs, get_inferior_args (),
acb618c
+		     sizeof (psargs) - strlen (psargs) - 1);
acb618c
 	}
acb618c
       note_data = (char *) linux_elfcore_write_prpsinfo (obfd, note_data,
acb618c
 							 note_size, fname,
acb618c
acb618c
acb618c
2007-04-28  Jan Kratochvil  <jan.kratochvil@redhat.com>
acb618c
acb618c
	* gdb.base/gcore-buffer-overflow.c, gdb.base/gcore-buffer-overflow.exp:
acb618c
	New files.
acb618c
acb618c
Index: ./gdb/testsuite/gdb.base/gcore-buffer-overflow.c
acb618c
===================================================================
acb618c
RCS file: gdb/testsuite/gdb.base/gcore-buffer-overflow.c
acb618c
diff -N gdb/testsuite/gdb.base/gcore-buffer-overflow.c
acb618c
--- /dev/null	1 Jan 1970 00:00:00 -0000
acb618c
+++ ./gdb/testsuite/gdb.base/gcore-buffer-overflow.c	28 Apr 2007 18:48:15 -0000
acb618c
@@ -0,0 +1,27 @@
acb618c
+/* Copyright 2007 Free Software Foundation, Inc.
acb618c
+
acb618c
+   This file is part of GDB.
acb618c
+
acb618c
+   This program is free software; you can redistribute it and/or modify
acb618c
+   it under the terms of the GNU General Public License as published by
acb618c
+   the Free Software Foundation; either version 2 of the License, or (at
acb618c
+   your option) any later version.
acb618c
+
acb618c
+   This program is distributed in the hope that it will be useful, but
acb618c
+   WITHOUT ANY WARRANTY; without even the implied warranty of
acb618c
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
acb618c
+   General Public License for more details.
acb618c
+
acb618c
+   You should have received a copy of the GNU General Public License
acb618c
+   along with this program; if not, write to the Free Software
acb618c
+   Foundation, Inc., 59 Temple Place - Suite 330,
acb618c
+   Boston, MA 02111-1307, USA.  */
acb618c
+
acb618c
+/*
acb618c
+ * Test GDB's internal buffers safety for the GCORE command.
acb618c
+ */
acb618c
+
acb618c
+int main (void)
acb618c
+{
acb618c
+  return 0;
acb618c
+}
acb618c
Index: ./gdb/testsuite/gdb.base/gcore-buffer-overflow.exp
acb618c
===================================================================
acb618c
RCS file: gdb/testsuite/gdb.base/gcore-buffer-overflow.exp
acb618c
diff -N gdb/testsuite/gdb.base/gcore-buffer-overflow.exp
acb618c
--- /dev/null	1 Jan 1970 00:00:00 -0000
acb618c
+++ ./gdb/testsuite/gdb.base/gcore-buffer-overflow.exp	28 Apr 2007 18:48:15 -0000
acb618c
@@ -0,0 +1,70 @@
acb618c
+# Copyright 2007 Free Software Foundation, Inc.
acb618c
+
acb618c
+# This program is free software; you can redistribute it and/or modify
acb618c
+# it under the terms of the GNU General Public License as published by
acb618c
+# the Free Software Foundation; either version 2 of the License, or
acb618c
+# (at your option) any later version.
acb618c
+# 
acb618c
+# This program is distributed in the hope that it will be useful,
acb618c
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
acb618c
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
acb618c
+# GNU General Public License for more details.
acb618c
+# 
acb618c
+# You should have received a copy of the GNU General Public License
acb618c
+# along with this program; if not, write to the Free Software
acb618c
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
acb618c
+
acb618c
+# Please email any bugs, comments, and/or additions to this file to:
acb618c
+# bug-gdb@prep.ai.mit.edu
acb618c
+
acb618c
+# Test GDB's internal buffers safety for the GCORE command.
acb618c
+
acb618c
+if $tracelevel then {
acb618c
+	strace $tracelevel
acb618c
+}
acb618c
+
acb618c
+set prms_id 0
acb618c
+set bug_id 0
acb618c
+
acb618c
+set testfile "gcore-buffer-overflow"
acb618c
+set srcfile  ${testfile}.c
acb618c
+# The ${binfile} basename needs to exceed 80 characters (`sizeof (psargs)')
acb618c
+# plus some additional data to overwrite the stack frame.
acb618c
+set pattern  01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
acb618c
+set binfile  ${objdir}/${subdir}/${testfile}-${pattern}
acb618c
+
acb618c
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
acb618c
+     untested gcore.exp
acb618c
+     return -1
acb618c
+}
acb618c
+
acb618c
+# Start with a fresh gdb.
acb618c
+
acb618c
+gdb_exit
acb618c
+gdb_start
acb618c
+gdb_reinitialize_dir $srcdir/$subdir
acb618c
+gdb_load ${binfile}
acb618c
+
acb618c
+gdb_test "set args ${pattern}"	\
acb618c
+         ""			\
acb618c
+         "Set buffer exceeding arguments"
acb618c
+
acb618c
+if { ! [ runto_main ] } then {
acb618c
+    untested gcore-buffer-overflow.exp
acb618c
+    return -1
acb618c
+}
acb618c
+
acb618c
+set escapedfilename [string_to_regexp ${objdir}/${subdir}/gcore-buffer-overflow.test]
acb618c
+
acb618c
+set test "save a corefile"
acb618c
+gdb_test_multiple "gcore ${objdir}/${subdir}/gcore-buffer-overflow.test" $test {
acb618c
+    -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" {
acb618c
+	pass $test
acb618c
+    }
acb618c
+    -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" {
acb618c
+	unsupported $test
acb618c
+    }
acb618c
+    eof {
acb618c
+	fail $test
acb618c
+    }
acb618c
+}