public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/98247] New: gcc analyzer does not detect Flexible Array Member misuse
@ 2020-12-11 16:32 vince.a.bridgers at gmail dot com
  2021-03-19 14:08 ` [Bug analyzer/98247] RFE: detect Flexible Array Member misuse in analyzer dmalcolm at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: vince.a.bridgers at gmail dot com @ 2020-12-11 16:32 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 98247
           Summary: gcc analyzer does not detect Flexible Array Member
                    misuse
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vince.a.bridgers at gmail dot com
  Target Milestone: ---

This is more of a query than a bug at this point (or possible "feature
enhancement request"). This initial request follows a similar (but different)
issue filed against clang, see https://bugs.llvm.org/show_bug.cgi?id=48136. 

The modified reproducer is shown below. While I understand generally the
compiler cannot know how large a FAM is allocated to be, the question becomes
is there some way gcc analysis can track a beyond bounds memory access at
static analysis time and flag the below case as suspicious? Perhaps this can be
done by constraining the idiom, and indeed that is what some reliable and
secure programming standards do when this matters. Perhaps this is already
covered by gcc, and if so my apologies for missing it - feel free to close this
an invalid with explanation. If there's way to address this already in gcc 11
(or beyond) I'm interested in understanding this. 

Thanks 

$ gcc  --version
gcc (GCC) 11.0.0 20200516 (experimental)
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ gcc  -fanalyzer fam.c 
$ # no output, interpreted to mean no errors found. 



#include <stdlib.h>
#include <string.h>

struct str {
    size_t len;
    char data[];
};

int main(void)
{
    struct str *str = malloc(sizeof(str) + 10);
    if (str) {
        str->len = 10;
        memset(str->data, 'x', 10);
        free(str);
    }
    return 0;
}

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

end of thread, other threads:[~2022-09-09 21:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-11 16:32 [Bug c/98247] New: gcc analyzer does not detect Flexible Array Member misuse vince.a.bridgers at gmail dot com
2021-03-19 14:08 ` [Bug analyzer/98247] RFE: detect Flexible Array Member misuse in analyzer dmalcolm at gcc dot gnu.org
2022-08-26 18:00 ` dmalcolm at gcc dot gnu.org
2022-08-26 18:04 ` dmalcolm at gcc dot gnu.org
2022-09-09 21:11 ` cvs-commit at gcc dot gnu.org
2022-09-09 21:44 ` [Bug analyzer/98247] Analyzer fails to detect certain out-of-bounds uses of flexible array members dmalcolm 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).