public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug build/30669] New: [gdb/build] -Wall -O2 -fsanitize=thread build fails with Werror=stringop-truncation
@ 2023-07-23 21:35 vries at gcc dot gnu.org
  2023-07-26 15:06 ` [Bug build/30669] " cvs-commit at gcc dot gnu.org
  2023-07-26 15:08 ` vries at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: vries at gcc dot gnu.org @ 2023-07-23 21:35 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=30669

            Bug ID: 30669
           Summary: [gdb/build] -Wall -O2 -fsanitize=thread build fails
                    with Werror=stringop-truncation
           Product: gdb
           Version: HEAD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: build
          Assignee: unassigned at sourceware dot org
          Reporter: vries at gcc dot gnu.org
  Target Milestone: ---

I did a build with CFLAGS/CXXFLAGS="-Wall -O2 -g -fsanitize=thread", and ran
into:
...
/data/vries/gdb/src/gdb/coffread.c: In function ‘void
coff_symfile_read(objfile*, symfile_add_flags)’:
/data/vries/gdb/src/gdb/coffread.c:1374:15: error: ‘char*
__builtin_strncpy(char*, const char*, long unsigned int)’ output may be
truncated copying 14 bytes from a string of length 19
[-Werror=stringop-truncation]
 1374 |       strncpy (buffer, aux_entry->x_file.x_n.x_fname, FILNMLEN);
      |               ^
...

I managed to write a minimal reproducer:
...
$ cat test.c
#include <string.h>

#define BUFSIZ 8193
#define FILNMLEN 14

static char x_fname[20];

static char buffer[BUFSIZ];

void
foo (void)
{
  strncpy (buffer, x_fname, FILNMLEN);
  buffer[FILNMLEN] = '\0';
}
$ gcc -O2 -Wall test.c -c -fsanitize=thread
test.c: In function ‘foo’:
test.c:13:3: warning: ‘strncpy’ output may be truncated copying 14 bytes from a
string of length 19 [-Wstringop-truncation]
   13 |   strncpy (buffer, x_fname, FILNMLEN);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...

This seems to be related to confusion about what the size of x_fname is, due to
commit 60ebc257517 ("Fixes a buffer overflow when compiling assembler for the
MinGW targets.").

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug build/30669] [gdb/build] -Wall -O2 -fsanitize=thread build fails with Werror=stringop-truncation
  2023-07-23 21:35 [Bug build/30669] New: [gdb/build] -Wall -O2 -fsanitize=thread build fails with Werror=stringop-truncation vries at gcc dot gnu.org
@ 2023-07-26 15:06 ` cvs-commit at gcc dot gnu.org
  2023-07-26 15:08 ` vries at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-07-26 15:06 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=30669

--- Comment #1 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Tom de Vries <vries@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=200546f1a33bd4e6d81d5bdef8d26836a7504bdb

commit 200546f1a33bd4e6d81d5bdef8d26836a7504bdb
Author: Tom de Vries <tdevries@suse.de>
Date:   Wed Jul 26 17:06:23 2023 +0200

    [gdb/build] Fix Wstringop-truncation in coff_getfilename

    When building gdb with -O2 -fsanitize-threads, I ran into
    a Werror=stringop-truncation.

    The problem is here in coff_getfilename in coffread.c:
    ...
          strncpy (buffer, aux_entry->x_file.x_n.x_fname, FILNMLEN);
          buffer[FILNMLEN] = '\0';
    ...

    The constant FILNMLEN is expected to designate the size of
    aux_entry->x_file.x_n.x_fname, but that's no longer the case since commit
    60ebc257517 ("Fixes a buffer overflow when compiling assembler for the
MinGW
    targets.").

    Fix this by using "sizeof (aux_entry->x_file.x_n.x_fname)" instead.

    Likewise in xcoffread.c.

    Tested on x86_64-linux.

    Approved-By: Tom Tromey <tom@tromey.com>

    PR build/30669
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30669

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug build/30669] [gdb/build] -Wall -O2 -fsanitize=thread build fails with Werror=stringop-truncation
  2023-07-23 21:35 [Bug build/30669] New: [gdb/build] -Wall -O2 -fsanitize=thread build fails with Werror=stringop-truncation vries at gcc dot gnu.org
  2023-07-26 15:06 ` [Bug build/30669] " cvs-commit at gcc dot gnu.org
@ 2023-07-26 15:08 ` vries at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: vries at gcc dot gnu.org @ 2023-07-26 15:08 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=30669

Tom de Vries <vries at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
   Target Milestone|---                         |14.1
             Status|NEW                         |RESOLVED

--- Comment #2 from Tom de Vries <vries at gcc dot gnu.org> ---
Fixed.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

end of thread, other threads:[~2023-07-26 15:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-23 21:35 [Bug build/30669] New: [gdb/build] -Wall -O2 -fsanitize=thread build fails with Werror=stringop-truncation vries at gcc dot gnu.org
2023-07-26 15:06 ` [Bug build/30669] " cvs-commit at gcc dot gnu.org
2023-07-26 15:08 ` vries at gcc dot gnu.org

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).