I'm working with a test case that actively exhausts the number of file descriptors to check that our system is resilient to that, and UBSan produces spurious undefined behaviour reports. This is due to the call to pipe in IsAccessibleMemoryRange in sanitizer_posix_libcdep.cpp, which attempts to create a pipe to check whether a particular block of memory is accessible. When there are no more file descriptors, that call will fail (returns -1), but it does not mean that the memory is in fact inaccessible. In these circumstances, I think it's best to give the program under test the benefit of the doubt and not report undefined behaviour. With this patch, IsAccessibleMemoryRange returns true if errno indicates that pipe failed because there are no file descriptors left.
Trivial example:
// Compile with: -fsanitize=undefined -fno-omit-frame-pointer // // Run with: bash -c "ulimit -n 4 ; ./ubsan-issue" // (triggers the issue with -n 4, but not with -n 5; your numbers may vary) // // Complaint: // ubsan-issue.cpp:16:23: runtime error: member call on address 0x000000639c00 which does not point to an object of type 'std::basic_ostream<char>' // 0x000000639c00: note: object has invalid vptr // <memory cannot be printed> // SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ubsan-issue.cpp:16:23 in int main(void) { std::cout << "text" << std::endl; return 0; }
clang-format not found in user’s local PATH; not linting file.