public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [pushed 0/2] Minor -fsanitize=address fixes
@ 2020-03-20 14:36 Tom Tromey
  2020-03-20 14:36 ` [pushed 1/2] Avoid stringop-truncation errors Tom Tromey
  2020-03-20 14:36 ` [pushed 2/2] Fix assert in c-exp.y Tom Tromey
  0 siblings, 2 replies; 3+ messages in thread
From: Tom Tromey @ 2020-03-20 14:36 UTC (permalink / raw)
  To: gdb-patches

I tried -fsanitize=address today and this found a couple of bugs.

The first problem was some new stringop-truncation build errors.
These are fixed in the first patch.

The second problem was an address sanitizer failure in a relatively
new assertion.  This is fixed in the second patch.

I'm checking these in directly because they are obvious fixes.

There are still some remaining sanitizer failures in the test suite,
but these seem more complicated to fix.

Tom



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [pushed 1/2] Avoid stringop-truncation errors
  2020-03-20 14:36 [pushed 0/2] Minor -fsanitize=address fixes Tom Tromey
@ 2020-03-20 14:36 ` Tom Tromey
  2020-03-20 14:36 ` [pushed 2/2] Fix assert in c-exp.y Tom Tromey
  1 sibling, 0 replies; 3+ messages in thread
From: Tom Tromey @ 2020-03-20 14:36 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

I configured with -fsanitize=address and built gdb.  linux-tdep.c and
ada-tasks.c failed to build due to some stringop-truncation errors,
e.g.:

In function ‘char* strncpy(char*, const char*, size_t)’,
    inlined from ‘int linux_fill_prpsinfo(elf_internal_linux_prpsinfo*)’ at ../../binutils-gdb/gdb/linux-tdep.c:1742:11,
    inlined from ‘char* linux_make_corefile_notes(gdbarch*, bfd*, int*)’ at ../../binutils-gdb/gdb/linux-tdep.c:1878:27:
/usr/include/bits/string_fortified.h:106:34: error: ‘char* __builtin_strncpy(char*, const char*, long unsigned int)’ specified bound 81 equals destination size [-Werror=stringop-truncation]

This patch fixes the problem by using "sizeof - 1" in the call to
strndup, as recommended in the GCC manual.  This doesn't make a
difference here because the next line, in all cases, sets the final
element to '\0' anyway.

gdb/ChangeLog
2020-03-20  Tom Tromey  <tromey@adacore.com>

	* ada-tasks.c (read_atcb): Use smaller length in strncpy call.
	* linux-tdep.c (linux_fill_prpsinfo): Use smaller length in
	strncpy call.
---
 gdb/ChangeLog    | 6 ++++++
 gdb/ada-tasks.c  | 3 ++-
 gdb/linux-tdep.c | 4 ++--
 3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/gdb/ada-tasks.c b/gdb/ada-tasks.c
index 0a81c3c6922..589d5e84e0a 100644
--- a/gdb/ada-tasks.c
+++ b/gdb/ada-tasks.c
@@ -679,7 +679,8 @@ read_atcb (CORE_ADDR task_id, struct ada_task_info *task_info)
 		  task_name = p + 2;
 
 	      /* Copy the task name.  */
-	      strncpy (task_info->name, task_name, sizeof (task_info->name));
+	      strncpy (task_info->name, task_name,
+		       sizeof (task_info->name) - 1);
 	      task_info->name[sizeof (task_info->name) - 1] = 0;
 	    }
 	  else
diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
index b6374ce399c..e50946ce379 100644
--- a/gdb/linux-tdep.c
+++ b/gdb/linux-tdep.c
@@ -1729,7 +1729,7 @@ linux_fill_prpsinfo (struct elf_internal_linux_prpsinfo *p)
 
   /* Copying the program name.  Only the basename matters.  */
   basename = lbasename (fname.get ());
-  strncpy (p->pr_fname, basename, sizeof (p->pr_fname));
+  strncpy (p->pr_fname, basename, sizeof (p->pr_fname) - 1);
   p->pr_fname[sizeof (p->pr_fname) - 1] = '\0';
 
   infargs = get_inferior_args ();
@@ -1739,7 +1739,7 @@ linux_fill_prpsinfo (struct elf_internal_linux_prpsinfo *p)
   if (infargs != NULL)
     psargs = psargs + " " + infargs;
 
-  strncpy (p->pr_psargs, psargs.c_str (), sizeof (p->pr_psargs));
+  strncpy (p->pr_psargs, psargs.c_str (), sizeof (p->pr_psargs) - 1);
   p->pr_psargs[sizeof (p->pr_psargs) - 1] = '\0';
 
   xsnprintf (filename, sizeof (filename), "/proc/%d/stat", (int) pid);
-- 
2.21.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [pushed 2/2] Fix assert in c-exp.y
  2020-03-20 14:36 [pushed 0/2] Minor -fsanitize=address fixes Tom Tromey
  2020-03-20 14:36 ` [pushed 1/2] Avoid stringop-truncation errors Tom Tromey
@ 2020-03-20 14:36 ` Tom Tromey
  1 sibling, 0 replies; 3+ messages in thread
From: Tom Tromey @ 2020-03-20 14:36 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

The "restrict" patch added some asserts to c-exp.y, but one spot was
copy-pasted and referred to the wrong table.  This was pointed out by
-fsanitize=address.  This patch fixes the bug.

gdb/ChangeLog
2020-03-20  Tom Tromey  <tromey@adacore.com>

	* c-exp.y (lex_one_token): Fix assert.
---
 gdb/ChangeLog | 4 ++++
 gdb/c-exp.y   | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/gdb/c-exp.y b/gdb/c-exp.y
index 50a2eef98b5..a4efaab79c8 100644
--- a/gdb/c-exp.y
+++ b/gdb/c-exp.y
@@ -2580,7 +2580,7 @@ lex_one_token (struct parser_state *par_state, bool *is_quoted_name)
 	if ((tokentab2[i].flags & FLAG_CXX) != 0
 	    && par_state->language ()->la_language != language_cplus)
 	  break;
-	gdb_assert ((tokentab3[i].flags & FLAG_C) == 0);
+	gdb_assert ((tokentab2[i].flags & FLAG_C) == 0);
 
 	pstate->lexptr += 2;
 	yylval.opcode = tokentab2[i].opcode;
-- 
2.21.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-03-20 14:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-20 14:36 [pushed 0/2] Minor -fsanitize=address fixes Tom Tromey
2020-03-20 14:36 ` [pushed 1/2] Avoid stringop-truncation errors Tom Tromey
2020-03-20 14:36 ` [pushed 2/2] Fix assert in c-exp.y Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).