[compiler-rt] r190295 - [sanitizer] Fix PR17138.
Evgeniy Stepanov
eugeni.stepanov at gmail.com
Mon Sep 9 01:58:55 PDT 2013
Author: eugenis
Date: Mon Sep 9 03:58:54 2013
New Revision: 190295
URL: http://llvm.org/viewvc/llvm-project?rev=190295&view=rev
Log:
[sanitizer] Fix PR17138.
strerror_r on OSX returns a positive error code when the errno value is
unknown. Buffer contents are initialized in any case.
Added:
compiler-rt/trunk/lib/asan/lit_tests/TestCases/strerror_r_test.cc (with props)
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
Added: compiler-rt/trunk/lib/asan/lit_tests/TestCases/strerror_r_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/TestCases/strerror_r_test.cc?rev=190295&view=auto
==============================================================================
--- compiler-rt/trunk/lib/asan/lit_tests/TestCases/strerror_r_test.cc (added)
+++ compiler-rt/trunk/lib/asan/lit_tests/TestCases/strerror_r_test.cc Mon Sep 9 03:58:54 2013
@@ -0,0 +1,13 @@
+// RUN: %clangxx_asan -O0 %s -o %t && %t
+
+// Regression test for PR17138.
+
+#include <assert.h>
+#include <string.h>
+
+int main() {
+ char buf[1024];
+ char *res = (char *)strerror_r(300, buf, sizeof(buf));
+ assert(res != 0);
+ return 0;
+}
Propchange: compiler-rt/trunk/lib/asan/lit_tests/TestCases/strerror_r_test.cc
------------------------------------------------------------------------------
svn:eol-style = LF
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc?rev=190295&r1=190294&r2=190295&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Mon Sep 9 03:58:54 2013
@@ -1807,12 +1807,14 @@ INTERCEPTOR(char *, strerror_r, int errn
// writes message to buf.
// * GNU version returns message pointer, which points to either buf or some
// static storage.
- if (!res) {
+ SIZE_T posix_res = (SIZE_T)res;
+ if (posix_res < 1024 || posix_res > (SIZE_T) - 1024) {
// POSIX version. Spec is not clear on whether buf is NULL-terminated.
+ // At least on OSX, buf contents are valid even when the call fails.
SIZE_T sz = internal_strnlen(buf, buflen);
if (sz < buflen) ++sz;
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, sz);
- } else if ((SIZE_T)res < (SIZE_T) - 1024) {
+ } else {
// GNU version.
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, res, REAL(strlen)(res) + 1);
}
More information about the llvm-commits
mailing list