c5d972
commit 2a3224c53653214cbba2ec23424702193c80ea3b
c5d972
Author: Siddhesh Poyarekar <siddhesh@sourceware.org>
c5d972
Date:   Wed Dec 30 11:09:58 2020 +0530
c5d972
c5d972
    string: Enable __FORTIFY_LEVEL=3
c5d972
    
c5d972
    This change enhances fortified string functions to use
c5d972
    __builtin_dynamic_object_size under _FORTIFY_SOURCE=3 whenever the
c5d972
    compiler supports it.
c5d972
c5d972
# Conflicts:
c5d972
#	string/bits/string_fortified.h
c5d972
c5d972
Conflict resolved to retain __GNUC_PREREQ (5,0) macro check in RHEL-8
c5d972
glibc.
c5d972
c5d972
diff --git a/include/string.h b/include/string.h
c5d972
index 4d622f1c0305e78e..bbc97082661caf42 100644
c5d972
--- a/include/string.h
c5d972
+++ b/include/string.h
c5d972
@@ -119,10 +119,11 @@ libc_hidden_proto (__ffs)
c5d972
 void __explicit_bzero_chk_internal (void *, size_t, size_t)
c5d972
   __THROW __nonnull ((1)) attribute_hidden;
c5d972
 # define explicit_bzero(buf, len) \
c5d972
-  __explicit_bzero_chk_internal (buf, len, __bos0 (buf))
c5d972
+  __explicit_bzero_chk_internal (buf, len, __glibc_objsize0 (buf))
c5d972
 #elif !IS_IN (nonlib)
c5d972
 void __explicit_bzero_chk (void *, size_t, size_t) __THROW __nonnull ((1));
c5d972
-# define explicit_bzero(buf, len) __explicit_bzero_chk (buf, len, __bos0 (buf))
c5d972
+# define explicit_bzero(buf, len) __explicit_bzero_chk (buf, len,	      \
c5d972
+							__glibc_objsize0 (buf))
c5d972
 #endif
c5d972
 
c5d972
 libc_hidden_builtin_proto (memchr)
c5d972
diff --git a/string/bits/string_fortified.h b/string/bits/string_fortified.h
c5d972
index 4ed6755a6c1ca247..27ec273ec41cd81c 100644
c5d972
--- a/string/bits/string_fortified.h
c5d972
+++ b/string/bits/string_fortified.h
c5d972
@@ -31,13 +31,15 @@ __fortify_function void *
c5d972
 __NTH (memcpy (void *__restrict __dest, const void *__restrict __src,
c5d972
 	       size_t __len))
c5d972
 {
c5d972
-  return __builtin___memcpy_chk (__dest, __src, __len, __bos0 (__dest));
c5d972
+  return __builtin___memcpy_chk (__dest, __src, __len,
c5d972
+				 __glibc_objsize0 (__dest));
c5d972
 }
c5d972
 
c5d972
 __fortify_function void *
c5d972
 __NTH (memmove (void *__dest, const void *__src, size_t __len))
c5d972
 {
c5d972
-  return __builtin___memmove_chk (__dest, __src, __len, __bos0 (__dest));
c5d972
+  return __builtin___memmove_chk (__dest, __src, __len,
c5d972
+				  __glibc_objsize0 (__dest));
c5d972
 }
c5d972
 
c5d972
 #ifdef __USE_GNU
c5d972
@@ -45,7 +47,8 @@ __fortify_function void *
c5d972
 __NTH (mempcpy (void *__restrict __dest, const void *__restrict __src,
c5d972
 		size_t __len))
c5d972
 {
c5d972
-  return __builtin___mempcpy_chk (__dest, __src, __len, __bos0 (__dest));
c5d972
+  return __builtin___mempcpy_chk (__dest, __src, __len,
c5d972
+				  __glibc_objsize0 (__dest));
c5d972
 }
c5d972
 #endif
c5d972
 
c5d972
@@ -68,7 +71,8 @@ __NTH (memset (void *__dest, int __ch, size_t __len))
c5d972
       return __dest;
c5d972
     }
c5d972
 #endif
c5d972
-  return __builtin___memset_chk (__dest, __ch, __len, __bos0 (__dest));
c5d972
+  return __builtin___memset_chk (__dest, __ch, __len,
c5d972
+				 __glibc_objsize0 (__dest));
c5d972
 }
c5d972
 
c5d972
 #ifdef __USE_MISC
c5d972
@@ -80,21 +84,21 @@ void __explicit_bzero_chk (void *__dest, size_t __len, size_t __destlen)
c5d972
 __fortify_function void
c5d972
 __NTH (explicit_bzero (void *__dest, size_t __len))
c5d972
 {
c5d972
-  __explicit_bzero_chk (__dest, __len, __bos0 (__dest));
c5d972
+  __explicit_bzero_chk (__dest, __len, __glibc_objsize0 (__dest));
c5d972
 }
c5d972
 #endif
c5d972
 
c5d972
 __fortify_function char *
c5d972
 __NTH (strcpy (char *__restrict __dest, const char *__restrict __src))
c5d972
 {
c5d972
-  return __builtin___strcpy_chk (__dest, __src, __bos (__dest));
c5d972
+  return __builtin___strcpy_chk (__dest, __src, __glibc_objsize (__dest));
c5d972
 }
c5d972
 
c5d972
 #ifdef __USE_GNU
c5d972
 __fortify_function char *
c5d972
 __NTH (stpcpy (char *__restrict __dest, const char *__restrict __src))
c5d972
 {
c5d972
-  return __builtin___stpcpy_chk (__dest, __src, __bos (__dest));
c5d972
+  return __builtin___stpcpy_chk (__dest, __src, __glibc_objsize (__dest));
c5d972
 }
c5d972
 #endif
c5d972
 
c5d972
@@ -103,14 +107,16 @@ __fortify_function char *
c5d972
 __NTH (strncpy (char *__restrict __dest, const char *__restrict __src,
c5d972
 		size_t __len))
c5d972
 {
c5d972
-  return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
c5d972
+  return __builtin___strncpy_chk (__dest, __src, __len,
c5d972
+				  __glibc_objsize (__dest));
c5d972
 }
c5d972
 
c5d972
 #if __GNUC_PREREQ (4, 7) || __glibc_clang_prereq (2, 6)
c5d972
 __fortify_function char *
c5d972
 __NTH (stpncpy (char *__dest, const char *__src, size_t __n))
c5d972
 {
c5d972
-  return __builtin___stpncpy_chk (__dest, __src, __n, __bos (__dest));
c5d972
+  return __builtin___stpncpy_chk (__dest, __src, __n,
c5d972
+				  __glibc_objsize (__dest));
c5d972
 }
c5d972
 #else
c5d972
 extern char *__stpncpy_chk (char *__dest, const char *__src, size_t __n,
c5d972
@@ -132,7 +138,7 @@ __NTH (stpncpy (char *__dest, const char *__src, size_t __n))
c5d972
 __fortify_function char *
c5d972
 __NTH (strcat (char *__restrict __dest, const char *__restrict __src))
c5d972
 {
c5d972
-  return __builtin___strcat_chk (__dest, __src, __bos (__dest));
c5d972
+  return __builtin___strcat_chk (__dest, __src, __glibc_objsize (__dest));
c5d972
 }
c5d972
 
c5d972
 
c5d972
@@ -140,7 +146,8 @@ __fortify_function char *
c5d972
 __NTH (strncat (char *__restrict __dest, const char *__restrict __src,
c5d972
 		size_t __len))
c5d972
 {
c5d972
-  return __builtin___strncat_chk (__dest, __src, __len, __bos (__dest));
c5d972
+  return __builtin___strncat_chk (__dest, __src, __len,
c5d972
+				  __glibc_objsize (__dest));
c5d972
 }
c5d972
 
c5d972
 #endif /* bits/string_fortified.h */
c5d972
diff --git a/string/bits/strings_fortified.h b/string/bits/strings_fortified.h
c5d972
index d9b2804525cfa994..871515bd2cba1f8a 100644
c5d972
--- a/string/bits/strings_fortified.h
c5d972
+++ b/string/bits/strings_fortified.h
c5d972
@@ -22,13 +22,15 @@
c5d972
 __fortify_function void
c5d972
 __NTH (bcopy (const void *__src, void *__dest, size_t __len))
c5d972
 {
c5d972
-  (void) __builtin___memmove_chk (__dest, __src, __len, __bos0 (__dest));
c5d972
+  (void) __builtin___memmove_chk (__dest, __src, __len,
c5d972
+				  __glibc_objsize0 (__dest));
c5d972
 }
c5d972
 
c5d972
 __fortify_function void
c5d972
 __NTH (bzero (void *__dest, size_t __len))
c5d972
 {
c5d972
-  (void) __builtin___memset_chk (__dest, '\0', __len, __bos0 (__dest));
c5d972
+  (void) __builtin___memset_chk (__dest, '\0', __len,
c5d972
+				 __glibc_objsize0 (__dest));
c5d972
 }
c5d972
 
c5d972
 #endif