Skip to content

Commit e33bcb7

Browse files
committed
Feedback; add sanitizer_common test
1 parent 32b4ef6 commit e33bcb7

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,16 +1265,9 @@ INTERCEPTOR(int, prctl, int option, unsigned long arg2, unsigned long arg3,
12651265
internal_strncpy(buff, (char *)arg2, 15);
12661266
buff[15] = 0;
12671267
COMMON_INTERCEPTOR_SET_THREAD_NAME(ctx, buff);
1268-
} else if (res != 1 && option == PR_GET_NAME) {
1269-
unsigned long null_index = 0;
1268+
} else if (res == 0 && option == PR_GET_NAME) {
12701269
char *name = (char *)arg2;
1271-
while (null_index < 16 && name[null_index]) {
1272-
++null_index;
1273-
}
1274-
if (null_index > 15) {
1275-
null_index = 15;
1276-
}
1277-
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, (u64 *)arg2, null_index + 1);
1270+
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, name, internal_strlen(name) + 1);
12781271
} else if (res != -1 && option == PR_SCHED_CORE &&
12791272
arg2 == PR_SCHED_CORE_GET) {
12801273
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, (u64*)(arg5), sizeof(u64));

compiler-rt/test/msan/prctl.cpp renamed to compiler-rt/test/msan/Linux/prctl.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// RUN: %clangxx_msan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
2-
// REQUIRES: linux
32

43
#include <linux/prctl.h>
54
#include <sys/prctl.h>

compiler-rt/test/sanitizer_common/TestCases/Linux/prctl.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <assert.h>
44
#include <errno.h>
55
#include <stdint.h>
6+
#include <string.h>
67
#include <sys/mman.h>
78
#include <sys/prctl.h>
89

@@ -60,5 +61,14 @@ int main() {
6061
}
6162
munmap(p, 128);
6263

64+
res = prctl(PR_SET_NAME, "tname");
65+
if (res == 0) {
66+
char name[16];
67+
res = prctl(PR_GET_NAME, name);
68+
if (res == 0) {
69+
assert(!strcmp(name, "tname"));
70+
}
71+
}
72+
6373
return 0;
6474
}

0 commit comments

Comments
 (0)