Skip to content

Commit 6cba4d4

Browse files
[analyzer] CStringChecker: bail out when arguments of copy function are not pointers
1 parent 2a0d7f8 commit 6cba4d4

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,10 @@ ProgramStateRef CStringChecker::CheckOverlap(CheckerContext &C,
672672

673673
ProgramStateRef stateTrue, stateFalse;
674674

675+
if (!First.Expression->getType()->isAnyPointerType() ||
676+
!Second.Expression->getType()->isAnyPointerType())
677+
return state;
678+
675679
// Assume different address spaces cannot overlap.
676680
if (First.Expression->getType()->getPointeeType().getAddressSpace() !=
677681
Second.Expression->getType()->getPointeeType().getAddressSpace())

clang/test/Analysis/buffer-overlap.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,19 @@ void test_snprintf6() {
9696
char b[4] = {0};
9797
snprintf(a, sizeof(a), "%s", b); // no-warning
9898
}
99+
100+
101+
void memcpy(int dst, int src, size_t size); // expected-warning{{incompatible redeclaration of library function 'memcpy'}} expected-note{{'memcpy' is a builtin with type 'void *(void *, const void *, __size_t)' (aka 'void *(void *, const void *, unsigned long)')}}
102+
void test_memcpy_proxy() {
103+
memcpy(42, 42, 42);
104+
}
105+
106+
void strcpy(int dst, char *src); // expected-warning{{incompatible redeclaration of library function 'strcpy'}} expected-note{{'strcpy' is a builtin with type 'char *(char *, const char *)'}}
107+
void test_strcpy_proxy() {
108+
strcpy(42, (char *)42);
109+
}
110+
111+
void strxfrm(int dst, char *src, size_t size); // expected-warning{{incompatible redeclaration of library function 'strxfrm'}} expected-note{{'strxfrm' is a builtin with type '__size_t (char *, const char *, __size_t)' (aka 'unsigned long (char *, const char *, unsigned long)')}}
112+
void test_strxfrm_proxy() {
113+
strxfrm(42, (char *)42, 42);
114+
}

0 commit comments

Comments
 (0)