[llvm-bugs] [Bug 36510] New: ASan: posix_memalign returns invalid value when allocation fails (macOS)

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Feb 25 13:31:14 PST 2018


https://bugs.llvm.org/show_bug.cgi?id=36510

            Bug ID: 36510
           Summary: ASan: posix_memalign returns invalid value when
                    allocation fails (macOS)
           Product: compiler-rt
           Version: unspecified
          Hardware: PC
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: compiler-rt
          Assignee: unassignedbugs at nondot.org
          Reporter: jbc.engelen at gmail.com
                CC: llvm-bugs at lists.llvm.org

Reproducing testcase:
```cpp
#include <iostream>
#include <stdlib.h>

int main()
{
    void* result;
    int code = posix_memalign(&result, 1, ~size_t(0));

    std::cout << code << std::endl;
}
```

The output on macOS with XCode 9:
❯ clang++ memalign.cpp -o memaligncpp
❯ ./memaligncpp
22

But with ASan:
❯ clang++ memalign.cpp -fsanitize=address -o memaligncpp
❯ ASAN_OPTIONS=allocator_may_return_null=1 ./memaligncpp
-1

"-1" is an invalid return value.

This is related to https://bugs.llvm.org/show_bug.cgi?id=32968 which appears to
have been fixed on Linux. On Linux, `posix_memalign` is intercepted and
overridden by `asan_posix_memalign`, but that's not the case on macOS.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180225/242b2659/attachment.html>


More information about the llvm-bugs mailing list