public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug other/94647] New: [10 Regression] wrong diagnostic with -Werror=format-security
@ 2020-04-18 11:13 doko at debian dot org
  2020-04-18 17:07 ` [Bug middle-end/94647] [10 Regression] bogus -Warray-bounds on strncpy into a larger member array from a smaller array msebor at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: doko at debian dot org @ 2020-04-18 11:13 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94647

            Bug ID: 94647
           Summary: [10 Regression] wrong diagnostic with
                    -Werror=format-security
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: other
          Assignee: unassigned at gcc dot gnu.org
          Reporter: doko at debian dot org
  Target Milestone: ---

[forwarded from https://bugs.debian.org/958062]

seen with trunk 20200417, works with the gcc-9 branch.

$ cat testcase.c
/* Compile with gcc-10 -O2 -c testcase.c -Wall -Wformat -Werror=format-security
*/

#include <string.h>

struct a
{
        int pad;
        char string[512];
};

struct b
{
        int pad;
        char string[256];
};

int f(struct a *d, struct b *s)
{
        int l;

        /* No warning here, so GCC 10 assumes that d->string is properly
         * null terminated. */
        l = strlen(d->string);

        /* Warning here, GCC 10 assumes that d->string is *not* properly
         * null terminated */
        strncpy(d->string, s->string, sizeof(d->string));

        return l;
}


$ gcc-10 -O2 -c testcase.c -Wall -Wformat -Werror=format-security
In file included from /usr/include/string.h:495,
                 from testcase.c:3:
In function ‘strncpy’,
    inlined from ‘f’ at testcase.c:27:2:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:10: warning:
‘__builtin_strncpy’ offset [260, 511] from the object at ‘s’ is out of the
bounds of referenced subobject ‘string’ with type ‘char[256]’ at offset 4
[-Warray-bounds]
  106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos
(__dest));
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
testcase.c: In function ‘f’:
testcase.c:14:7: note: subobject ‘string’ declared here
   14 |  char string[256];
      |       ^~~~~~

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

end of thread, other threads:[~2020-04-22 15:35 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-18 11:13 [Bug other/94647] New: [10 Regression] wrong diagnostic with -Werror=format-security doko at debian dot org
2020-04-18 17:07 ` [Bug middle-end/94647] [10 Regression] bogus -Warray-bounds on strncpy into a larger member array from a smaller array msebor at gcc dot gnu.org
2020-04-20  7:01 ` rguenth at gcc dot gnu.org
2020-04-20 17:35 ` msebor at gcc dot gnu.org
2020-04-20 21:29 ` msebor at gcc dot gnu.org
2020-04-21 17:13 ` cvs-commit at gcc dot gnu.org
2020-04-21 17:15 ` msebor at gcc dot gnu.org
2020-04-22 14:59 ` jakub at gcc dot gnu.org
2020-04-22 15:35 ` cvs-commit 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).