Commit Graph

2374 Commits

Author SHA1 Message Date
Chandler Carruth 1a48dc5ed6 Fix a veritable conucopia of bugs in the readdir_r interceptors.
First, the reason I came here: I forgot to look at readdir64_r which had
the exact same bug as readdir_r. However, upon applying the same
quick-fix and testing it I discovered that it still didn't work at all.
As a consequence, I spent some time studying the code and thinking about
it and fixed several other problems.

Second, the code was checking for a null entry and result pointer, but
there is no indication that null pointers are viable here. Certainly,
the spec makes it extremely clear that there is no non-error case where
the implementation of readdir_r fails to dereference the 'result'
pointer and store NULL to it. Thus, our checking for a non-null 'result'
pointer before reflecting that write in the instrumentation was
trivially dead. Remove it.

Third, the interceptor was marking the write to the actual dirent struct
by looking at the entry pointer, but nothing in the spec requires that
the dirent struct written is actually written into the entry structure
provided. A threadlocal buffer would be just as conforming, and the spec
goes out of its way to say the pointer to the *actual* result dirent
struct is stored into *result, so *that* is where the interceptor should
reflect a write occuring. This also obviates the need to even consider
whether the 'entry' parameter is null.

Fourth, I got to the bottom of why nothing at all worked in readdir64_r
-- the interceptor structure for dirent64 was completely wrong in that
it was the same as dirent. I fixed this struct to be correct (64-bit
inode and 64-bit offset! just a 64-bit offset isn't enough!) and added
several missing tests for the size and layout of this struct.

llvm-svn: 186109
2013-07-11 18:51:40 +00:00
Sergey Matveev 29e787d456 [sanitizer] Remove optional arguments from clone() invocation.
Unbreaks compilation on older systems. Patch by Andy Jost.

llvm-svn: 186103
2013-07-11 16:37:44 +00:00
Evgeniy Stepanov 9240838655 [sanitizer] More checks in mbstowcs-like interceptors.
llvm-svn: 186004
2013-07-10 14:17:46 +00:00
Evgeniy Stepanov 123fdb3413 [sanitizer] Fix handling of edge cases in mbstowcs-like interceptors.
llvm-svn: 186002
2013-07-10 14:01:51 +00:00
Chandler Carruth 28c1b294b8 Fix a bug in the readdir_r interceptor: when we reach the end of the
directory stream, the entry is not written to, instead *result is set to
NULL and the entry is not written to at all.

I'm still somewhat suspicious of the correct instrumention here --
I feel like it should be marking the written range as the pointer in
*result and the length (*result)->d_reclen in case the implementation
decides not to use the passed-in entry (if that's even allowed).
Finally, the definition of 'struct dirent' analog used in the
interceptor is wrong in 32-bit mode with _FILE_OFFSET_BITS=64 as it hard
codes the use of a pointer-sized offset.

I've added a somewhat goofy test for the bug I fixed via ASan --
suggestions on how to better test the interceptor logic itself welcome.

llvm-svn: 185998
2013-07-10 09:50:29 +00:00
Peter Collingbourne 2c60538ddd [asan] Update blacklists to use categories.
Differential Revision: http://llvm-reviews.chandlerc.com/D1094

llvm-svn: 185980
2013-07-09 22:04:28 +00:00
Evgeniy Stepanov 7160fb6511 [sanitizer] Update glob64 interceptor to handle GLOB_ALTDIRFUNC as well.
llvm-svn: 185935
2013-07-09 12:34:25 +00:00
Evgeniy Stepanov faba61a7bc [sanitizer] Support GLOB_ALTDIRFUNC in glob interceptor.
llvm-svn: 185932
2013-07-09 12:07:59 +00:00
Evgeniy Stepanov 77ef78a0a5 [sanitizer] Intercept realpath and canonicalize_file_name.
Handle realpath(path, NULL) form.

llvm-svn: 185921
2013-07-09 09:53:37 +00:00
Evgeniy Stepanov f60c75a644 [sanitizer] Wrap lines >80 chars.
llvm-svn: 185920
2013-07-09 09:47:36 +00:00
Evgeniy Stepanov 8495b84076 [asan] Fix windows build.
llvm-svn: 185917
2013-07-09 09:29:19 +00:00
Evgeniy Stepanov f7f252d025 [sanitizer] Syscall handlers for clock_gettime and clock_getres.
llvm-svn: 185913
2013-07-09 08:54:59 +00:00
Sergey Matveev ddd7b6a1c8 [lsan] Fix test.
llvm-svn: 185817
2013-07-08 14:08:05 +00:00
Sergey Matveev bdeff959a1 [lsan] Handle fork() correctly.
Update the main thread's os_id on every pthread_create, and before
initiating leak checking. This ensures that we have the correct os_id even if we
have forked after Init().

llvm-svn: 185815
2013-07-08 12:57:24 +00:00
Alexey Samsonov 852d8a4c18 [LSan] Use overridable hook to report error summary
llvm-svn: 185805
2013-07-08 10:59:52 +00:00
Evgeniy Stepanov c2e3ba9eed [sanitizer] Fix mac build.
llvm-svn: 185706
2013-07-05 15:04:56 +00:00
Evgeniy Stepanov 628d727749 [msan] Intercept pthread_key_create.
llvm-svn: 185693
2013-07-05 12:31:07 +00:00
Evgeniy Stepanov 0d1d35aeba [sanitizer] Disable ptrace interception on non-x86(_64).
Patch by Hal Finkel.

llvm-svn: 185686
2013-07-05 08:57:47 +00:00
Alexander Potapenko 4f73dea69d [ASan] Close stderr before launching atos in asan_symbolize.py
llvm-svn: 185631
2013-07-04 14:21:49 +00:00
Evgeniy Stepanov 717e0cd2a7 [sanitizer] Intercept tcgetattr.
llvm-svn: 185626
2013-07-04 14:03:31 +00:00
Evgeniy Stepanov db615c186f [sanitizer] More interceptors.
bcopy
strtoimax, strtoumax
mbstowcs, mbsrtowcs, mbsnrtowcs
wcstombs, wcsrtombs, wcsnrtombs

llvm-svn: 185624
2013-07-04 13:19:41 +00:00
Alexander Potapenko d0c91acb58 [ASan] Do not protect the malloc zone created by malloc_zone_create() on Snow Leopard and earlier systems.
Fixes https://code.google.com/p/address-sanitizer/issues/detail?id=208

llvm-svn: 185621
2013-07-04 10:16:12 +00:00
Sergey Matveev 22614e5e3f [sanitizer] Fix memory leak in sanitizer_common discovered by LeakSanitizer.
llvm-svn: 185536
2013-07-03 13:45:13 +00:00
Evgeniy Stepanov 1bd0fe447f [sanitizer] Fix Android build.
llvm-svn: 185432
2013-07-02 14:51:31 +00:00
Evgeniy Stepanov aa23bd83e5 [msan] Intercept mempcpy, wmempcpy.
llvm-svn: 185431
2013-07-02 14:49:24 +00:00
Evgeniy Stepanov 69a387e6ae [sanitizer] Fix GLOB_NOMATCH behaviour and refactor the interceptor a bit.
llvm-svn: 185428
2013-07-02 14:08:52 +00:00
Evgeniy Stepanov 165d759a6a [sanitizer] Intercept mbtowc, mbrtowc, get_current_dir_name.
Move getcwd to common interceptors.

llvm-svn: 185424
2013-07-02 13:34:44 +00:00
Evgeniy Stepanov 1df4dfe87a [sanitizer] Intercept setlocale.
llvm-svn: 185416
2013-07-02 09:23:45 +00:00
Alexey Samsonov 4798a08df8 [ASan] try to fix Windows build
llvm-svn: 185345
2013-07-01 16:38:38 +00:00
Alexey Samsonov 9857ca2564 [ASan] Properly disable strict init-order checking when pthread_create is called
llvm-svn: 185342
2013-07-01 16:16:41 +00:00
Evgeniy Stepanov 654688bed5 [msan] Intercept stpcpy.
llvm-svn: 185340
2013-07-01 15:19:37 +00:00
Evgeniy Stepanov 8a4e24ea8b [sanitizer] Intercept getnameinfo.
llvm-svn: 185338
2013-07-01 13:51:31 +00:00
Alexey Samsonov 7a1ad5e605 Change __sanitizer_symbolize_demangle hook return type to 'int'
llvm-svn: 185326
2013-07-01 11:20:56 +00:00
Alexander Potapenko 0fde89f2aa [ASan] Cache atos processes to make Darwin symbolication faster.
Patch by Jesse Ruderman<jruderman@gmail.com>

llvm-svn: 185325
2013-07-01 10:51:31 +00:00
Sergey Matveev 6b5a492091 [sanitizer] Use the correct macro to check glibc version.
llvm-svn: 185324
2013-07-01 10:15:29 +00:00
Alexey Samsonov c3832f7788 [ASan] Add sanity test for asan_symbolize.py script
llvm-svn: 185318
2013-07-01 09:15:19 +00:00
Evgeniy Stepanov d6e856f722 [sanitizer] Fix build with older kernels.
PTRACE_SETREGSET & PTRACE_GETREGSET may be missing from linux headers.

llvm-svn: 185317
2013-07-01 09:10:34 +00:00
Alexey Samsonov cc510707af [ASan] Remove leading underscores from function names in output tests
llvm-svn: 185315
2013-07-01 08:41:45 +00:00
Alexey Samsonov 8918140809 Hide mlock/munlock info message under verbosity flag.
llvm-svn: 185314
2013-07-01 08:25:29 +00:00
Alexey Samsonov e71f37c1cd Define the path to llvm-symbolizer tool in a common config to reduce copy-paste
llvm-svn: 185286
2013-06-30 14:47:38 +00:00
Richard Smith 079fe209f5 Fix typo found by Clang fix for extern "C" function handling.
llvm-svn: 185234
2013-06-28 22:28:37 +00:00
Alexey Samsonov 13f89cd19b [ASan] Remove %symbolize from lit tests: we now use external symbolizer instead of python script
llvm-svn: 185163
2013-06-28 15:52:44 +00:00
Sergey Matveev 202881d1fe [lsan] Fix build again.
llvm-svn: 185157
2013-06-28 15:23:15 +00:00
Sergey Matveev b3fa575f7b [lsan] Fix build.
llvm-svn: 185156
2013-06-28 15:18:06 +00:00
Sergey Matveev 6672004c47 [lsan] When verbosity > 1, always print suppressions and summary (even if no leaks found).
Also fix an output bug.

llvm-svn: 185153
2013-06-28 15:05:16 +00:00
Sergey Matveev 2b19ee3da8 [lsan] Add suppression support.
llvm-svn: 185152
2013-06-28 14:38:31 +00:00
Evgeniy Stepanov a127039258 [sanitizer] Disable all ptrace-related definitions on Android.
llvm-svn: 185150
2013-06-28 14:18:10 +00:00
Alexey Samsonov 002d764f21 [ASan] Migrate lit tests to external symbolizer from asan_symbolize.py script
llvm-svn: 185148
2013-06-28 12:50:12 +00:00
Alexey Samsonov 6a5b0758ec Demangle names using pluggable internal symbolizer if possible
llvm-svn: 185146
2013-06-28 12:30:24 +00:00
Evgeniy Stepanov 4aef0ee57d [sanitizer] Fix an unfortunate typo and disable ptrace interception on Android.
llvm-svn: 185145
2013-06-28 12:16:03 +00:00