This is an archive of the discontinued LLVM Phabricator instance.

[asan] Fix the freopen interceptor to allow NULL instead of a filename
ClosedPublic

Authored by kubamracek on Jul 21 2015, 7:04 AM.

Diff Detail

Event Timeline

kubamracek updated this revision to Diff 30253.Jul 21 2015, 7:04 AM
kubamracek retitled this revision from to [asan] Fix the freopen interceptor to allow NULL instead of a filename.
kubamracek updated this object.
kubamracek added reviewers: kcc, glider, samsonov.
kubamracek added subscribers: llvm-commits, kcc, glider and 2 others.
glider accepted this revision.Jul 21 2015, 7:16 AM
glider edited edge metadata.

The case of path==NULL is not covered in the Ubuntu manpage for freopen, but this behavior is mandated by POSIX and is in fact implemented in Glibc.
Therefore LGTM

test/asan/TestCases/Posix/freopen.cc
10

Please add the return statement.

This revision is now accepted and ready to land.Jul 21 2015, 7:16 AM
This revision was automatically updated to reflect the committed changes.

Hm, the Linux buildbot didn't like this change: http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/19256/steps/check-asan%20in%20gcc%20build/logs/stdio

Interestingly, only the i386 variant failed. Could it be that that system's libc really doesn't support NULL for freopen? Alexander, could you help me out here? I reverted the patch until we figure this out.

Thanks!

When built with -m32 and without ASan, this testcase does not crash for me.
Trying to reproduce with ASan.

When built with -m32 and without ASan, this testcase does not crash for me.
Trying to reproduce with ASan.

Hi Alexander, did you find any cause of the test failure? Thanks!

Hi Kuba,

the crash reproduced for me, but I couldn't find the cause, and then I
got distracted.
I'll try to take a look again next week.

Alex

kubamracek updated this revision to Diff 33311.Aug 27 2015, 4:27 AM
kubamracek edited edge metadata.
kubamracek removed rL LLVM as the repository for this revision.

OK, I was able to reproduce the i386 Linux test failure. It looks like it has little to do with the actual patch/fix, but instead it's a more general issue with versioned symbols from glibc – freopen is a versioned symbol (and incompatible between versions), and when it's intercepted, a wrong version is called. Even this fails (with or without this patch):

FILE *fp = fopen("/dev/null", "w");
freopen("/dev/null", "r", fp);
fclose(fp);

This seems to be a Linux-specific issue, and frankly, I don't know what to do about it. In the meantime, I'm suggesting to commit this patch without the testcase. Updating the diff.

I suggest to commit the patch anyway, but mark it as disabled.

I suggest to commit the patch anyway, but mark it as disabled.

What's the proper way to mark a test as disabled? I'm only aware of XFAIL and REQUIRES marks.

I think XFAIL is fine.

I think XFAIL is fine.

I don't think that'll work, since this only fails on i386 Linux and works fine on other platforms and architectures...

Marking the patch with REQUIRES: asan-64-bits to skip the test on i386 Linux (where it fails due to an unrelated issue with glibc versioned symbols). XFAIL wouldn't work here, because the test actually passes on all other platforms/architectures.

So is this okay to commit?

Yes. Please go ahead.

Landed in r246435.