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