[ASan] add interceptor for strncat
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@158198 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/asan/asan_interceptors.cc b/lib/asan/asan_interceptors.cc
index f6b6754..22f6c31 100644
--- a/lib/asan/asan_interceptors.cc
+++ b/lib/asan/asan_interceptors.cc
@@ -71,6 +71,7 @@
char* index(const char *string, int c);
# endif
char* strcat(char *to, const char* from); // NOLINT
+char *strncat(char *to, const char* from, uptr size);
char* strcpy(char *to, const char* from); // NOLINT
char* strncpy(char *to, const char* from, uptr size);
int strcmp(const char *s1, const char* s2);
@@ -504,6 +505,22 @@
return REAL(strcat)(to, from); // NOLINT
}
+INTERCEPTOR(char*, strncat, char *to, const char *from, uptr size) {
+ ENSURE_ASAN_INITED();
+ if (FLAG_replace_str && size > 0) {
+ uptr from_length = internal_strnlen(from, size);
+ ASAN_READ_RANGE(from, Min(size, from_length + 1));
+ uptr to_length = REAL(strlen)(to);
+ ASAN_READ_RANGE(to, to_length);
+ ASAN_WRITE_RANGE(to + to_length, from_length + 1);
+ if (from_length > 0) {
+ CHECK_RANGES_OVERLAP("strncat", to, to_length + 1,
+ from, Min(size, from_length + 1));
+ }
+ }
+ return REAL(strncat)(to, from, size);
+}
+
INTERCEPTOR(int, strcmp, const char *s1, const char *s2) {
if (!asan_inited) {
return internal_strcmp(s1, s2);
@@ -759,6 +776,7 @@
ASAN_INTERCEPT_FUNC(strcmp);
ASAN_INTERCEPT_FUNC(strcpy); // NOLINT
ASAN_INTERCEPT_FUNC(strlen);
+ ASAN_INTERCEPT_FUNC(strncat);
ASAN_INTERCEPT_FUNC(strncmp);
ASAN_INTERCEPT_FUNC(strncpy);
#if !defined(_WIN32)