public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug sanitizer/98920] New: [10/11 Regression] uses regexec without support for REG_STARTEND with -fsanitize=address
@ 2021-02-01 16:42 doko at debian dot org
  2021-02-02  8:14 ` [Bug sanitizer/98920] " rguenth at gcc dot gnu.org
                   ` (21 more replies)
  0 siblings, 22 replies; 23+ messages in thread
From: doko at debian dot org @ 2021-02-01 16:42 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 98920
           Summary: [10/11 Regression] uses regexec without support for
                    REG_STARTEND with -fsanitize=address
           Product: gcc
           Version: 10.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: sanitizer
          Assignee: unassigned at gcc dot gnu.org
          Reporter: doko at debian dot org
                CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org,
                    jakub at gcc dot gnu.org, kcc at gcc dot gnu.org, marxin at gcc dot gnu.org
  Target Milestone: ---

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

When gcc-10 compiles with -fsanitize=address, it substitutes any calls
to regexec with a version that does not support REG_STARTEND.  This
makes code that is compiled fail unexpectedly or even produce spurious
sanitization errors, since with that option the buffer need not be
NUL-terminated.

While REG_STARTEND is not in POSIX, it is found on the BSDs and Linux
and users may reasonably rely on the fact that it is present on those
systems.

This issue has caused a bug in the Git testsuite as seen at
https://lore.kernel.org/git/20200117174931.GA8958@coredump.intra.peff.net/T/#t.

I've attached a testcase.  Without -fsanitize=address, it succeeds
silently.  With -fsanitize=address, it fails and prints an error.

Please either fix the regexec implementation such that it is fully
functional compared to the version in glibc or disable the sanitization
of regexec until it has feature parity.

$ cat test.c 
#include <stdio.h>
#include <sys/types.h>
#include <regex.h>

int main(void)
{
    regex_t r;
    const char s[] = "ban\0ana";
    regmatch_t pmatch[10];
    pmatch[0].rm_so = 0;
    pmatch[0].rm_eo = sizeof(s);
    if (regcomp(&r, "ana", 0))
        return 2;
    if (regexec(&r, s, sizeof(pmatch)/sizeof(pmatch[0]), pmatch, REG_STARTEND))
{
        fprintf(stderr, "failed to match\n");
        regfree(&r);
        return 3;
    }
    regfree(&r);
    return 0;
}


$ gcc-9 -fsanitize=address test.c && ./a.out 

$ gcc-10 -fsanitize=address test.c && ./a.out 
failed to match

$ gcc-11 -fsanitize=address test.c && ./a.out 
failed to match

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

end of thread, other threads:[~2021-03-09 13:15 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-01 16:42 [Bug sanitizer/98920] New: [10/11 Regression] uses regexec without support for REG_STARTEND with -fsanitize=address doko at debian dot org
2021-02-02  8:14 ` [Bug sanitizer/98920] " rguenth at gcc dot gnu.org
2021-02-02 10:04 ` marxin at gcc dot gnu.org
2021-02-02 12:52 ` marxin at gcc dot gnu.org
2021-02-04 11:08 ` jakub at gcc dot gnu.org
2021-02-04 11:19 ` jakub at gcc dot gnu.org
2021-02-05 12:39 ` marxin at gcc dot gnu.org
2021-02-05 13:07 ` jakub at gcc dot gnu.org
2021-02-05 13:16 ` fw at gcc dot gnu.org
2021-02-05 13:34 ` jakub at gcc dot gnu.org
2021-02-05 14:29 ` fw at gcc dot gnu.org
2021-02-05 14:41 ` jakub at gcc dot gnu.org
2021-02-09  9:33 ` marxin at gcc dot gnu.org
2021-02-09  9:35 ` marxin at gcc dot gnu.org
2021-02-09  9:54 ` jakub at gcc dot gnu.org
2021-02-09 11:50 ` marxin at gcc dot gnu.org
2021-02-26 12:40 ` rguenth at gcc dot gnu.org
2021-03-08 14:55 ` cvs-commit at gcc dot gnu.org
2021-03-08 14:56 ` marxin at gcc dot gnu.org
2021-03-09 10:47 ` ro at gcc dot gnu.org
2021-03-09 11:16 ` jakub at gcc dot gnu.org
2021-03-09 12:06 ` ro at CeBiTec dot Uni-Bielefeld.DE
2021-03-09 13:15 ` 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).