[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
This commit is contained in:
Matt Morehouse 2020-08-14 08:01:40 -07:00
parent 25ce634172
commit c1f9c1c13c
2 changed files with 6 additions and 6 deletions

View File

@ -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;

View File

@ -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);
}