mirror of
				https://git.proxmox.com/git/llvm-toolchain
				synced 2025-11-04 04:13:47 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			208 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			Diff
		
	
	
	
	
	
			
		
		
	
	
			208 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			Diff
		
	
	
	
	
	
---
 | 
						|
 clang/include/clang/Basic/Builtins.def                    |    8 +-
 | 
						|
 clang/lib/AST/Decl.cpp                                    |   12 +--
 | 
						|
 clang/lib/Sema/SemaChecking.cpp                           |   11 +-
 | 
						|
 clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp |    6 -
 | 
						|
 clang/test/Sema/builtins.c                                |   11 +-
 | 
						|
 clang/test/Sema/warn-strlcpycat-size.c                    |   55 --------------
 | 
						|
 6 files changed, 25 insertions(+), 78 deletions(-)
 | 
						|
 | 
						|
Index: llvm-toolchain-7_7~+rc1/clang/include/clang/Basic/Builtins.def
 | 
						|
===================================================================
 | 
						|
--- llvm-toolchain-7_7~+rc1.orig/clang/include/clang/Basic/Builtins.def
 | 
						|
+++ llvm-toolchain-7_7~+rc1/clang/include/clang/Basic/Builtins.def
 | 
						|
@@ -503,8 +503,8 @@ BUILTIN(__builtin___memset_chk, "v*v*izz
 | 
						|
 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")
 | 
						|
@@ -952,8 +952,8 @@ LIBBUILTIN(getcontext, "iK*",     "fj",
 | 
						|
 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: llvm-toolchain-7_7~+rc1/clang/lib/AST/Decl.cpp
 | 
						|
===================================================================
 | 
						|
--- llvm-toolchain-7_7~+rc1.orig/clang/lib/AST/Decl.cpp
 | 
						|
+++ llvm-toolchain-7_7~+rc1/clang/lib/AST/Decl.cpp
 | 
						|
@@ -3591,13 +3591,13 @@ unsigned FunctionDecl::getMemoryFunction
 | 
						|
   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: llvm-toolchain-7_7~+rc1/clang/lib/Sema/SemaChecking.cpp
 | 
						|
===================================================================
 | 
						|
--- llvm-toolchain-7_7~+rc1.orig/clang/lib/Sema/SemaChecking.cpp
 | 
						|
+++ llvm-toolchain-7_7~+rc1/clang/lib/Sema/SemaChecking.cpp
 | 
						|
@@ -1224,8 +1224,8 @@ Sema::CheckBuiltinFunctionCall(FunctionD
 | 
						|
   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:
 | 
						|
@@ -4064,9 +4064,10 @@ bool Sema::CheckFunctionCall(FunctionDec
 | 
						|
     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: llvm-toolchain-7_7~+rc1/clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
 | 
						|
===================================================================
 | 
						|
--- llvm-toolchain-7_7~+rc1.orig/clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
 | 
						|
+++ llvm-toolchain-7_7~+rc1/clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
 | 
						|
@@ -240,9 +240,9 @@ GenericTaintChecker::TaintPropagationRul
 | 
						|
     case Builtin::BIstrncpy:
 | 
						|
     case Builtin::BIstrncat:
 | 
						|
       return TaintPropagationRule(1, 2, 0, true);
 | 
						|
-    case Builtin::BIstrlcpy:
 | 
						|
-    case Builtin::BIstrlcat:
 | 
						|
-      return TaintPropagationRule(1, 2, 0, false);
 | 
						|
+//    case Builtin::BIstrlcpy:
 | 
						|
+//    case Builtin::BIstrlcat:
 | 
						|
+//      return TaintPropagationRule(1, 2, 0, false);
 | 
						|
     case Builtin::BIstrndup:
 | 
						|
       return TaintPropagationRule(0, 1, ReturnValueIndex);
 | 
						|
 
 | 
						|
Index: llvm-toolchain-7_7~+rc1/clang/test/Sema/builtins.c
 | 
						|
===================================================================
 | 
						|
--- llvm-toolchain-7_7~+rc1.orig/clang/test/Sema/builtins.c
 | 
						|
+++ llvm-toolchain-7_7~+rc1/clang/test/Sema/builtins.c
 | 
						|
@@ -190,11 +190,11 @@ 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));
 | 
						|
+//  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}}
 | 
						|
+//  ptr = __builtin___strlcat_chk(dst, src, sizeof(dst), sizeof(dst)); // expected-warning {{incompatible integer to pointer conversion}}
 | 
						|
 }
 | 
						|
 
 | 
						|
 void no_ms_builtins() {
 | 
						|
@@ -209,12 +209,12 @@ void unavailable() {
 | 
						|
 }
 | 
						|
 
 | 
						|
 // 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);
 | 
						|
+//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 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}} \\
 | 
						|
@@ -229,6 +229,7 @@ void Test19(void)
 | 
						|
         __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 {{'__builtin___strlcat_chk' will always overflow destination buffer}}
 | 
						|
+                                                                   */
 | 
						|
 }
 | 
						|
 
 | 
						|
 // rdar://11076881
 | 
						|
Index: llvm-toolchain-7_7~+rc1/clang/test/Sema/warn-strlcpycat-size.c
 | 
						|
===================================================================
 | 
						|
--- llvm-toolchain-7_7~+rc1.orig/clang/test/Sema/warn-strlcpycat-size.c
 | 
						|
+++ /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}}
 | 
						|
-}
 |