@@ -539,6 +539,17 @@ INTERCEPTOR(char *, strcpy, char *to, const char *from) {
539
539
return REAL (strcpy)(to, from);
540
540
}
541
541
542
+ // Windows doesn't always define the strdup identifier,
543
+ // and when it does it's a macro defined to either _strdup
544
+ // or _strdup_dbg, _strdup_dbg ends up calling _strdup, so
545
+ // we want to intercept that. push/pop_macro are used to avoid problems
546
+ // if this file ends up including <string.h> in the future.
547
+ # if SANITIZER_WINDOWS
548
+ # pragma push_macro("strdup")
549
+ # undef strdup
550
+ # define strdup _strdup
551
+ # endif
552
+
542
553
INTERCEPTOR (char *, strdup, const char *s) {
543
554
void *ctx;
544
555
ASAN_INTERCEPTOR_ENTER (ctx, strdup);
@@ -556,7 +567,7 @@ INTERCEPTOR(char*, strdup, const char *s) {
556
567
return reinterpret_cast <char *>(new_mem);
557
568
}
558
569
559
- #if ASAN_INTERCEPT___STRDUP
570
+ # if ASAN_INTERCEPT___STRDUP
560
571
INTERCEPTOR (char *, __strdup, const char *s) {
561
572
void *ctx;
562
573
ASAN_INTERCEPTOR_ENTER (ctx, strdup);
@@ -742,7 +753,7 @@ void InitializeAsanInterceptors() {
742
753
ASAN_INTERCEPT_FUNC (strncat);
743
754
ASAN_INTERCEPT_FUNC (strncpy);
744
755
ASAN_INTERCEPT_FUNC (strdup);
745
- #if ASAN_INTERCEPT___STRDUP
756
+ # if ASAN_INTERCEPT___STRDUP
746
757
ASAN_INTERCEPT_FUNC (__strdup);
747
758
#endif
748
759
#if ASAN_INTERCEPT_INDEX && ASAN_USE_ALIAS_ATTRIBUTE_FOR_INDEX
@@ -831,6 +842,10 @@ void InitializeAsanInterceptors() {
831
842
VReport (1 , " AddressSanitizer: libc interceptors initialized\n " );
832
843
}
833
844
845
+ # if SANITIZER_WINDOWS
846
+ # pragma pop_macro("strdup")
847
+ # endif
848
+
834
849
} // namespace __asan
835
850
836
851
#endif // !SANITIZER_FUCHSIA
0 commit comments