[LLVMbugs] [Bug 17138] New: strerror_r interceptor incorrectly checks return value: POSIX may return any non-zero value for failure

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Sep 6 17:01:27 PDT 2013


http://llvm.org/bugs/show_bug.cgi?id=17138

            Bug ID: 17138
           Summary: strerror_r interceptor incorrectly checks return
                    value: POSIX may return any non-zero value for failure
           Product: compiler-rt
           Version: unspecified
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: compiler-rt
          Assignee: unassignedbugs at nondot.org
          Reporter: dfarler at apple.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Created attachment 11153
  --> http://llvm.org/bugs/attachment.cgi?id=11153&action=edit
Sample C code to print all error strings in OS X with strerror_r

Per the POSIX specification:

"The strerror_r() function shall map the error number in errnum to a
locale-dependent error message string and shall return the string in the buffer
pointed to by strerrbuf, with length buflen."
(http://pubs.opengroup.org/onlinepubs/9699919799/functions/strerror_r.html)

OS X strerror_r will return EINVAL (22) and populate the buffer with "Unknown
error: %d" for all errnos > 106 as they are undefined (see
/usr/include/sys/errno.h).

In
http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc?diff_format=h&revision=187876&view=
, the check for whether this is a POSIX strerror_r states that "POSIX version
returns 0 on success, negative error code on failure...". This is incorrect but
then goes on to only determine POSIX with res == 0.

Additionally, POSIX specifies:

"If the value of errnum is a valid error number, the message string shall
indicate what error occurred; if the value of errnum is zero, the message
string shall either be an empty string or indicate that no error occurred;
otherwise, if these functions complete successfully, the message string shall
indicate that an unknown error occurred."
(http://pubs.opengroup.org/onlinepubs/9699919799/functions/strerror_r.html)

In this regard, OS X complies with POSIX for strerror_r.

STEPS TO REPRODUCE:
Compile the attached file with and without -fsanitize=address on OS X.

RESULTS:
- EXC_BAD_ACCESS with -fsanitize=address
- Successful exit with "Unknown error: %d" for errnos > 106 without

-- 
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/20130907/01c99a9c/attachment.html>


More information about the llvm-bugs mailing list