[compiler-rt] c1f9c1c - [DFSan] Fix parameters to strtoull wrapper.

Matt Morehouse via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 14 08:02:42 PDT 2020


Author: Matt Morehouse
Date: 2020-08-14T08:02:30-07:00
New Revision: c1f9c1c13cff0468964c3f4059b6857aaf818841

URL: https://github.com/llvm/llvm-project/commit/c1f9c1c13cff0468964c3f4059b6857aaf818841
DIFF: https://github.com/llvm/llvm-project/commit/c1f9c1c13cff0468964c3f4059b6857aaf818841.diff

LOG: [DFSan] Fix parameters to strtoull wrapper.

base and nptr_label were swapped, which meant we were passing nptr's
shadow as the base to the operation.  Usually, the shadow is 0, which
causes strtoull to guess the correct base from the string prefix (e.g.,
0x means base-16 and 0 means base-8), hiding this bug.  Adjust the test
case to expose the bug.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D85935

Added: 
    

Modified: 
    compiler-rt/lib/dfsan/dfsan_custom.cpp
    compiler-rt/test/dfsan/custom.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/dfsan/dfsan_custom.cpp b/compiler-rt/lib/dfsan/dfsan_custom.cpp
index 1acd2d47d154..eb26bea188ae 100644
--- a/compiler-rt/lib/dfsan/dfsan_custom.cpp
+++ b/compiler-rt/lib/dfsan/dfsan_custom.cpp
@@ -607,8 +607,8 @@ unsigned long int __dfsw_strtoul(const char *nptr, char **endptr, int base,
 
 SANITIZER_INTERFACE_ATTRIBUTE
 long long unsigned int __dfsw_strtoull(const char *nptr, char **endptr,
-                                       dfsan_label nptr_label,
-                                       int base, dfsan_label endptr_label,
+                                       int base, dfsan_label nptr_label,
+                                       dfsan_label endptr_label,
                                        dfsan_label base_label,
                                        dfsan_label *ret_label) {
   char *tmp_endptr;

diff  --git a/compiler-rt/test/dfsan/custom.cpp b/compiler-rt/test/dfsan/custom.cpp
index 22dc395f3e81..e1ccf44ae7e0 100644
--- a/compiler-rt/test/dfsan/custom.cpp
+++ b/compiler-rt/test/dfsan/custom.cpp
@@ -537,24 +537,24 @@ void test_strtoll() {
 }
 
 void test_strtoul() {
-  char buf[] = "0xffffffffffffaa";
+  char buf[] = "ffffffffffffaa";
   char *endptr = NULL;
   dfsan_set_label(i_label, buf + 1, 1);
   dfsan_set_label(j_label, buf + 2, 1);
   long unsigned int ret = strtol(buf, &endptr, 16);
   assert(ret == 72057594037927850);
-  assert(endptr == buf + 16);
+  assert(endptr == buf + 14);
   ASSERT_LABEL(ret, i_j_label);
 }
 
 void test_strtoull() {
-  char buf[] = "0xffffffffffffffaa";
+  char buf[] = "ffffffffffffffaa";
   char *endptr = NULL;
   dfsan_set_label(i_label, buf + 1, 1);
   dfsan_set_label(j_label, buf + 2, 1);
   long long unsigned int ret = strtoull(buf, &endptr, 16);
   assert(ret == 0xffffffffffffffaa);
-  assert(endptr == buf + 18);
+  assert(endptr == buf + 16);
   ASSERT_LABEL(ret, i_j_label);
 }
 


        


More information about the llvm-commits mailing list