public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* GCC ASAN breaks glob()?
@ 2023-03-26 19:00 Paul Smith
  2023-03-26 19:17 ` Andrew Pinski
  0 siblings, 1 reply; 2+ messages in thread
From: Paul Smith @ 2023-03-26 19:00 UTC (permalink / raw)
  To: gcc

OK here's something super-strange I discovered:

Enabling -faddress=sanitize in GCC, causes the glob(3) function to
misbehave.

I'm using GCC 11.3 / glibc 2.35 (x86_64 native).  I have this simple
program:

$ cat /tmp/tstglob.c
#include <stdio.h>
#include <glob.h>

int main(int argc, char *argv[])
{
    glob_t gl = {0};
    int res = glob(argv[1], 0, NULL, &gl);

    switch (res)
    {
        case 0: printf("success\n"); break;
        case GLOB_NOMATCH: printf("no match\n"); break;
        default: printf("unknown: %d\n", res); break;
    }

    return 0;
}

Now I create a symlink that doesn't point to anything:

  $ ln -s nosuchfile /tmp/badlink
  $ ls -al /tmp/badlink
  lrwxrwxrwx 1 pds pds 10 Mar 26 14:52 /tmp/badlink -> nosuchfile

Now I compile the above program normally and run it:

  $ gcc -o /tmp/tstglob /tmp/tstglob.c
  $ /tmp/tstglob /tmp/badlink
  success

This is what I expect: the symlink does exist even though it doesn't
point to anything so glob() should return it.

But now if I compile with ASAN:

  $ gcc -fsanitize=address -o /tmp/tstglob /tmp/tstglob.c
  $ /tmp/tstglob /tmp/badlink
  no match

...?!?!?!

Is there something in the ASAN library that takes over glob(3) and
installs a different version (there have been plenty of versions of
glob(3) over the years in glibc which behave incorrectly when faced
with broken symlinks, heavens knows...) that overrides the glibc
version?

Or...??

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

* Re: GCC ASAN breaks glob()?
  2023-03-26 19:00 GCC ASAN breaks glob()? Paul Smith
@ 2023-03-26 19:17 ` Andrew Pinski
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Pinski @ 2023-03-26 19:17 UTC (permalink / raw)
  To: paul; +Cc: gcc

On Sun, Mar 26, 2023 at 12:01 PM Paul Smith <paul@mad-scientist.net> wrote:
>
> OK here's something super-strange I discovered:
>
> Enabling -faddress=sanitize in GCC, causes the glob(3) function to
> misbehave.
>
> I'm using GCC 11.3 / glibc 2.35 (x86_64 native).  I have this simple
> program:

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

Thanks,
Andrew

>
> $ cat /tmp/tstglob.c
> #include <stdio.h>
> #include <glob.h>
>
> int main(int argc, char *argv[])
> {
>     glob_t gl = {0};
>     int res = glob(argv[1], 0, NULL, &gl);
>
>     switch (res)
>     {
>         case 0: printf("success\n"); break;
>         case GLOB_NOMATCH: printf("no match\n"); break;
>         default: printf("unknown: %d\n", res); break;
>     }
>
>     return 0;
> }
>
> Now I create a symlink that doesn't point to anything:
>
>   $ ln -s nosuchfile /tmp/badlink
>   $ ls -al /tmp/badlink
>   lrwxrwxrwx 1 pds pds 10 Mar 26 14:52 /tmp/badlink -> nosuchfile
>
> Now I compile the above program normally and run it:
>
>   $ gcc -o /tmp/tstglob /tmp/tstglob.c
>   $ /tmp/tstglob /tmp/badlink
>   success
>
> This is what I expect: the symlink does exist even though it doesn't
> point to anything so glob() should return it.
>
> But now if I compile with ASAN:
>
>   $ gcc -fsanitize=address -o /tmp/tstglob /tmp/tstglob.c
>   $ /tmp/tstglob /tmp/badlink
>   no match
>
> ...?!?!?!
>
> Is there something in the ASAN library that takes over glob(3) and
> installs a different version (there have been plenty of versions of
> glob(3) over the years in glibc which behave incorrectly when faced
> with broken symlinks, heavens knows...) that overrides the glibc
> version?
>
> Or...??

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

end of thread, other threads:[~2023-03-26 19:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-26 19:00 GCC ASAN breaks glob()? Paul Smith
2023-03-26 19:17 ` Andrew Pinski

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