[Clang][Sema] Add fortify warnings for stpcpy (#141646)
As mentioned in https://github.com/llvm/llvm-project/issues/142230, I am adding fortify warnings for functions missing in Clang and I am starting with stpcpy.
This commit is contained in:
@@ -1257,6 +1257,8 @@ void Sema::checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD,
|
||||
switch (BuiltinID) {
|
||||
default:
|
||||
return;
|
||||
case Builtin::BI__builtin_stpcpy:
|
||||
case Builtin::BIstpcpy:
|
||||
case Builtin::BI__builtin_strcpy:
|
||||
case Builtin::BIstrcpy: {
|
||||
DiagID = diag::warn_fortify_strlen_overflow;
|
||||
@@ -1265,6 +1267,7 @@ void Sema::checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD,
|
||||
break;
|
||||
}
|
||||
|
||||
case Builtin::BI__builtin___stpcpy_chk:
|
||||
case Builtin::BI__builtin___strcpy_chk: {
|
||||
DiagID = diag::warn_fortify_strlen_overflow;
|
||||
SourceSize = ComputeStrLenArgument(1);
|
||||
|
||||
@@ -71,6 +71,14 @@ void call_strcpy_nowarn(void) {
|
||||
__builtin_strcpy(dst, src);
|
||||
}
|
||||
|
||||
void call_stpcpy(void) {
|
||||
const char *const src = "abcd";
|
||||
char dst1[5];
|
||||
char dst2[4];
|
||||
__builtin_stpcpy(dst1, src);
|
||||
__builtin_stpcpy(dst2, src); // expected-warning {{'stpcpy' will always overflow; destination buffer has size 4, but the source string has length 5 (including NUL byte)}}
|
||||
}
|
||||
|
||||
void call_memmove(void) {
|
||||
char s1[10], s2[20];
|
||||
__builtin_memmove(s2, s1, 20);
|
||||
|
||||
Reference in New Issue
Block a user