strlcpy_strlcat_warning_removed
authorLLVM Packaging Team <pkg-llvm-team@lists.alioth.debian.org>
Tue, 21 Jul 2020 16:29:06 +0000 (17:29 +0100)
committerSylvestre Ledru <sylvestre@debian.org>
Tue, 21 Jul 2020 16:29:06 +0000 (17:29 +0100)
Gbp-Pq: Name 23-strlcpy_strlcat_warning_removed.diff

clang/include/clang/Basic/Builtins.def
clang/lib/AST/Decl.cpp
clang/lib/Sema/SemaChecking.cpp
clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
clang/test/Sema/builtins.c
clang/test/Sema/warn-strlcpycat-size.c [deleted file]

index 1a6c85ce2dd3689726132ebb367be80cc5259fde..06dbb7956b243ded9248ad715abecc651717ee9d 100644 (file)
@@ -546,8 +546,8 @@ BUILTIN(__builtin___memset_chk, "v*v*izz", "nF")
 BUILTIN(__builtin___stpcpy_chk, "c*c*cC*z", "nF")
 BUILTIN(__builtin___strcat_chk, "c*c*cC*z", "nF")
 BUILTIN(__builtin___strcpy_chk, "c*c*cC*z", "nF")
-BUILTIN(__builtin___strlcat_chk, "zc*cC*zz", "nF")
-BUILTIN(__builtin___strlcpy_chk, "zc*cC*zz", "nF")
+//BUILTIN(__builtin___strlcat_chk, "zc*cC*zz", "nF")
+//BUILTIN(__builtin___strlcpy_chk, "zc*cC*zz", "nF")
 BUILTIN(__builtin___strncat_chk, "c*c*cC*zz", "nF")
 BUILTIN(__builtin___strncpy_chk, "c*c*cC*zz", "nF")
 BUILTIN(__builtin___stpncpy_chk, "c*c*cC*zz", "nF")
@@ -1020,8 +1020,8 @@ LIBBUILTIN(getcontext, "iK*",     "fj",   "setjmp.h", ALL_LANGUAGES)
 LIBBUILTIN(_longjmp, "vJi",       "fr",    "setjmp.h", ALL_GNU_LANGUAGES)
 LIBBUILTIN(siglongjmp, "vSJi",    "fr",    "setjmp.h", ALL_GNU_LANGUAGES)
 // non-standard but very common
-LIBBUILTIN(strlcpy, "zc*cC*z",    "f",     "string.h", ALL_GNU_LANGUAGES)
-LIBBUILTIN(strlcat, "zc*cC*z",    "f",     "string.h", ALL_GNU_LANGUAGES)
+//LIBBUILTIN(strlcpy, "zc*cC*z",    "f",     "string.h", ALL_GNU_LANGUAGES)
+//LIBBUILTIN(strlcat, "zc*cC*z",    "f",     "string.h", ALL_GNU_LANGUAGES)
 //   id objc_msgSend(id, SEL, ...)
 LIBBUILTIN(objc_msgSend, "GGH.",   "f",     "objc/message.h", OBJC_LANG)
 // long double objc_msgSend_fpret(id self, SEL op, ...)
index 0d30f64b992e0cd6a76c87ec187bb7c2687748ab..bd57cd28d9edf436dac49fc15f499d8b19563855 100644 (file)
@@ -3897,13 +3897,13 @@ unsigned FunctionDecl::getMemoryFunctionKind() const {
   case Builtin::BImemmove:
     return Builtin::BImemmove;
 
-  case Builtin::BIstrlcpy:
-  case Builtin::BI__builtin___strlcpy_chk:
-    return Builtin::BIstrlcpy;
+//  case Builtin::BIstrlcpy:
+//  case Builtin::BI__builtin___strlcpy_chk:
+//    return Builtin::BIstrlcpy;
 
-  case Builtin::BIstrlcat:
-  case Builtin::BI__builtin___strlcat_chk:
-    return Builtin::BIstrlcat;
+//  case Builtin::BIstrlcat:
+//  case Builtin::BI__builtin___strlcat_chk:
+//    return Builtin::BIstrlcat;
 
   case Builtin::BI__builtin_memcmp:
   case Builtin::BImemcmp:
index 74742023d1b33dd2d5e34e44e91771796706ac15..34be34f9d8f6b068393178507051abfe96137ec1 100644 (file)
@@ -416,8 +416,8 @@ void Sema::checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD,
   case Builtin::BI__builtin___memcpy_chk:
   case Builtin::BI__builtin___memmove_chk:
   case Builtin::BI__builtin___memset_chk:
-  case Builtin::BI__builtin___strlcat_chk:
-  case Builtin::BI__builtin___strlcpy_chk:
+//  case Builtin::BI__builtin___strlcat_chk:
+//  case Builtin::BI__builtin___strlcpy_chk:
   case Builtin::BI__builtin___strncat_chk:
   case Builtin::BI__builtin___strncpy_chk:
   case Builtin::BI__builtin___stpncpy_chk:
@@ -4535,9 +4535,10 @@ bool Sema::CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall,
     return false;
 
   // Handle memory setting and copying functions.
-  if (CMId == Builtin::BIstrlcpy || CMId == Builtin::BIstrlcat)
-    CheckStrlcpycatArguments(TheCall, FnInfo);
-  else if (CMId == Builtin::BIstrncat)
+//  if (CMId == Builtin::BIstrlcpy || CMId == Builtin::BIstrlcat)
+//    CheckStrlcpycatArguments(TheCall, FnInfo);
+//  else
+  if (CMId == Builtin::BIstrncat)
     CheckStrncatArguments(TheCall, FnInfo);
   else
     CheckMemaccessArguments(TheCall, CMId, FnInfo);
index 302d5bb1bea865a2cec5115ae3a7e7b677493a60..9c8558abf78bd1353b12a4cbbe5217bee2d5055f 100644 (file)
@@ -470,9 +470,9 @@ GenericTaintChecker::TaintPropagationRule::getTaintPropagationRule(
     case Builtin::BIstrncpy:
     case Builtin::BIstrncat:
       return TaintPropagationRule({1, 2}, {0, ReturnValueIndex});
-    case Builtin::BIstrlcpy:
-    case Builtin::BIstrlcat:
-      return TaintPropagationRule({1, 2}, {0});
+//    case Builtin::BIstrlcpy:
+//    case Builtin::BIstrlcat:
+//      return TaintPropagationRule({1, 2}, {0});
     case Builtin::BIstrndup:
       return TaintPropagationRule({0, 1}, {ReturnValueIndex});
 
index 1d41bcf9f0865cbc6a8a73098f862c37dc6cb9dd..9ab9306298d83b97dcd16786741af768b71ca5bc 100644 (file)
@@ -199,11 +199,9 @@ void test18() {
 
   ptr = __builtin___memccpy_chk(dst, src, '\037', sizeof(src), sizeof(dst));
   result = __builtin___strlcpy_chk(dst, src, sizeof(dst), sizeof(dst));
-  result = __builtin___strlcat_chk(dst, src, sizeof(dst), sizeof(dst));
 
   ptr = __builtin___memccpy_chk(dst, src, '\037', sizeof(src));      // expected-error {{too few arguments to function call}}
   ptr = __builtin___strlcpy_chk(dst, src, sizeof(dst), sizeof(dst)); // expected-warning {{incompatible integer to pointer conversion}}
-  ptr = __builtin___strlcat_chk(dst, src, sizeof(dst), sizeof(dst)); // expected-warning {{incompatible integer to pointer conversion}}
 }
 
 void no_ms_builtins() {
@@ -217,29 +215,6 @@ void unavailable() {
   __builtin_operator_delete(0); // expected-error {{'__builtin_operator_delete' is only available in C++}}
 }
 
-// rdar://18259539
-size_t strlcpy(char * restrict dst, const char * restrict src, size_t size);
-size_t strlcat(char * restrict dst, const char * restrict src, size_t size);
-
-void Test19(void)
-{
-        static char b[40];
-        static char buf[20];
-
-        strlcpy(buf, b, sizeof(b)); // expected-warning {{size argument in 'strlcpy' call appears to be size of the source; expected the size of the destination}} \\
-                                    // expected-note {{change size argument to be the size of the destination}}
-        __builtin___strlcpy_chk(buf, b, sizeof(b), __builtin_object_size(buf, 0)); // expected-warning {{size argument in '__builtin___strlcpy_chk' call appears to be size of the source; expected the size of the destination}} \
-                                    // expected-note {{change size argument to be the size of the destination}} \
-                                   // expected-warning {{'strlcpy' will always overflow; destination buffer has size 20, but size argument is 40}}
-
-        strlcat(buf, b, sizeof(b)); // expected-warning {{size argument in 'strlcat' call appears to be size of the source; expected the size of the destination}} \
-                                    // expected-note {{change size argument to be the size of the destination}}
-                                   
-        __builtin___strlcat_chk(buf, b, sizeof(b), __builtin_object_size(buf, 0)); // expected-warning {{size argument in '__builtin___strlcat_chk' call appears to be size of the source; expected the size of the destination}} \
-                                                                                   // expected-note {{change size argument to be the size of the destination}} \
-                                                                                  // expected-warning {{'strlcat' will always overflow; destination buffer has size 20, but size argument is 40}}
-}
-
 // rdar://11076881
 char * Test20(char *p, const char *in, unsigned n)
 {
diff --git a/clang/test/Sema/warn-strlcpycat-size.c b/clang/test/Sema/warn-strlcpycat-size.c
deleted file mode 100644 (file)
index 8babdde..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-// RUN: %clang_cc1 -Wstrlcpy-strlcat-size -verify -fsyntax-only %s
-
-typedef __SIZE_TYPE__ size_t;
-size_t strlcpy (char * restrict dst, const char * restrict src, size_t size);
-size_t strlcat (char * restrict dst, const char * restrict src, size_t size);
-size_t strlen (const char *s);
-
-char s1[100];
-char s2[200];
-char * s3;
-
-struct {
-  char f1[100];
-  char f2[100][3];
-} s4, **s5;
-
-int x;
-
-void f(void)
-{
-  strlcpy(s1, s2, sizeof(s1)); // no warning
-  strlcpy(s1, s2, sizeof(s2)); // expected-warning {{size argument in 'strlcpy' call appears to be size of the source; expected the size of the destination}} expected-note {{change size argument to be the size of the destination}}
-  strlcpy(s1, s3, strlen(s3)+1); // expected-warning {{size argument in 'strlcpy' call appears to be size of the source; expected the size of the destination}} expected-note {{change size argument to be the size of the destination}}
-  strlcat(s2, s3, sizeof(s3)); // expected-warning {{size argument in 'strlcat' call appears to be size of the source; expected the size of the destination}} expected-note {{change size argument to be the size of the destination}}
-  strlcpy(s4.f1, s2, sizeof(s2)); // expected-warning {{size argument in 'strlcpy' call appears to be size of the source; expected the size of the destination}} expected-note {{change size argument to be the size of the destination}}
-  strlcpy((*s5)->f2[x], s2, sizeof(s2)); // expected-warning {{size argument in 'strlcpy' call appears to be size of the source; expected the size of the destination}} expected-note {{change size argument to be the size of the destination}}
-  strlcpy(s1+3, s2, sizeof(s2)); // expected-warning {{size argument in 'strlcpy' call appears to be size of the source; expected the size of the destination}}
-}
-
-// Don't issue FIXIT for flexible arrays.
-struct S {
-  int y; 
-  char x[];
-};
-
-void flexible_arrays(struct S *s) {
-  char str[] = "hi";
-  strlcpy(s->x, str, sizeof(str));  // expected-warning {{size argument in 'strlcpy' call appears to be size of the source; expected the size of the destination}}
-}
-
-// Don't issue FIXIT for destinations of size 1.
-void size_1() {
-  char z[1];
-  char str[] = "hi";
-
-  strlcpy(z, str, sizeof(str));  // expected-warning {{size argument in 'strlcpy' call appears to be size of the source; expected the size of the destination}}
-}
-
-// Support VLAs.
-void vlas(int size) {
-  char z[size];
-  char str[] = "hi";
-
-  strlcpy(z, str, sizeof(str)); // expected-warning {{size argument in 'strlcpy' call appears to be size of the source; expected the size of the destination}} expected-note {{change size argument to be the size of the destination}}
-}