-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new interceptors: strlcpy(3) and strlcat(3)
Summary: NetBSD ships with strlcpy(3) and strlcat(3), a safe replacement of strcpy(3) and strcat(3). Hide both functions under SANITIZER_INTERCEPT_STRLCPY. Sponsored by <The NetBSD Foundation> Reviewers: joerg, vitalybuka Reviewed By: vitalybuka Subscribers: llvm-commits, kubamracek, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D42061 llvm-svn: 324034
- Loading branch information
1 parent
c7ef565
commit e2f8718
Showing
4 changed files
with
141 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
compiler-rt/test/sanitizer_common/TestCases/NetBSD/strlcat.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// RUN: %clangxx -O0 -g %s -o %t && %run %t | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
void test1() { | ||
const char src[] = "abc"; | ||
char dst[7] = {'x', 'y', 'z', 0}; | ||
size_t len; | ||
|
||
len = strlcat(dst, src, sizeof(dst)); | ||
printf("%s %zu ", dst, len); | ||
} | ||
|
||
void test2() { | ||
const char src[] = "abc"; | ||
char dst[7] = {0}; | ||
size_t len; | ||
|
||
len = strlcat(dst, src, sizeof(dst)); | ||
printf("%s %zu ", dst, len); | ||
} | ||
|
||
void test3() { | ||
const char src[] = "abc"; | ||
char dst[4] = {'x', 'y', 'z', 0}; | ||
size_t len; | ||
|
||
len = strlcat(dst, src, sizeof(dst)); | ||
printf("%s %zu ", dst, len); | ||
} | ||
|
||
void test4() { | ||
const char src[] = ""; | ||
char dst[4] = {'x', 'y', 'z', 0}; | ||
size_t len; | ||
|
||
len = strlcat(dst, src, sizeof(dst)); | ||
printf("%s %zu\n", dst, len); | ||
} | ||
|
||
int main(void) { | ||
test1(); | ||
test2(); | ||
test3(); | ||
test4(); | ||
|
||
// CHECK: xyzabc 6 abc 3 xyz 3 xyz 3 | ||
|
||
return 0; | ||
} |
52 changes: 52 additions & 0 deletions
52
compiler-rt/test/sanitizer_common/TestCases/NetBSD/strlcpy.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// RUN: %clangxx -O0 -g %s -o %t && %run %t | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
void test1() { | ||
const char src[] = "abc"; | ||
char dst[7] = {'x', 'y', 'z', 0}; | ||
size_t len; | ||
|
||
len = strlcpy(dst, src, sizeof(dst)); | ||
printf("%s %zu ", dst, len); | ||
} | ||
|
||
void test2() { | ||
const char src[] = "abc"; | ||
char dst[7] = {0}; | ||
size_t len; | ||
|
||
len = strlcat(dst, src, sizeof(dst)); | ||
printf("%s %zu ", dst, len); | ||
} | ||
|
||
void test3() { | ||
const char src[] = "abc"; | ||
char dst[4] = {'x', 'y', 'z', 0}; | ||
size_t len; | ||
|
||
len = strlcat(dst, src, sizeof(dst)); | ||
printf("%s %zu ", dst, len); | ||
} | ||
|
||
void test4() { | ||
const char src[] = ""; | ||
char dst[4] = {'x', 'y', 'z', 0}; | ||
size_t len; | ||
|
||
len = strlcat(dst, src, sizeof(dst)); | ||
printf("%s %zu\n", dst, len); | ||
} | ||
|
||
int main(void) { | ||
test1(); | ||
test2(); | ||
test3(); | ||
test4(); | ||
|
||
// CHECK: abc 3 abc 3 xyz 3 0 | ||
|
||
return 0; | ||
} |