public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "doko at debian dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug other/94647] New: [10 Regression] wrong diagnostic with -Werror=format-security
Date: Sat, 18 Apr 2020 11:13:39 +0000	[thread overview]
Message-ID: <bug-94647-4@http.gcc.gnu.org/bugzilla/> (raw)

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];
      |       ^~~~~~

             reply	other threads:[~2020-04-18 11:13 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-18 11:13 doko at debian dot org [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-94647-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).