|
|
c5d972 |
commit 7163ace3318d666d40771f5c8e7c4a148827070f
|
|
|
c5d972 |
Author: Siddhesh Poyarekar <siddhesh@sourceware.org>
|
|
|
c5d972 |
Date: Thu Nov 12 12:09:56 2020 +0530
|
|
|
c5d972 |
|
|
|
c5d972 |
Use __builtin___stpncpy_chk when available
|
|
|
c5d972 |
|
|
|
c5d972 |
The builtin has been available in gcc since 4.7.0 and in clang since
|
|
|
c5d972 |
2.6. This fixes stpncpy fortification with clang since it does a
|
|
|
c5d972 |
better job of plugging in __stpncpy_chk in the right place than the
|
|
|
c5d972 |
header hackery.
|
|
|
c5d972 |
|
|
|
c5d972 |
This has been tested by building and running all tests with gcc 10.2.1
|
|
|
c5d972 |
and also with clang tip as of a few days ago (just the tests in debug/
|
|
|
c5d972 |
since running all tests don't work with clang at the moment) to make
|
|
|
c5d972 |
sure that both compilers pass the stpncpy tests.
|
|
|
c5d972 |
|
|
|
c5d972 |
diff --git a/string/bits/string_fortified.h b/string/bits/string_fortified.h
|
|
|
c5d972 |
index a07ab0dbc8c8dd5b..4ed6755a6c1ca247 100644
|
|
|
c5d972 |
--- a/string/bits/string_fortified.h
|
|
|
c5d972 |
+++ b/string/bits/string_fortified.h
|
|
|
c5d972 |
@@ -106,7 +106,13 @@ __NTH (strncpy (char *__restrict __dest, const char *__restrict __src,
|
|
|
c5d972 |
return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
|
|
|
c5d972 |
}
|
|
|
c5d972 |
|
|
|
c5d972 |
-/* XXX We have no corresponding builtin yet. */
|
|
|
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 |
+}
|
|
|
c5d972 |
+#else
|
|
|
c5d972 |
extern char *__stpncpy_chk (char *__dest, const char *__src, size_t __n,
|
|
|
c5d972 |
size_t __destlen) __THROW;
|
|
|
c5d972 |
extern char *__REDIRECT_NTH (__stpncpy_alias, (char *__dest, const char *__src,
|
|
|
c5d972 |
@@ -120,6 +126,7 @@ __NTH (stpncpy (char *__dest, const char *__src, size_t __n))
|
|
|
c5d972 |
return __stpncpy_chk (__dest, __src, __n, __bos (__dest));
|
|
|
c5d972 |
return __stpncpy_alias (__dest, __src, __n);
|
|
|
c5d972 |
}
|
|
|
c5d972 |
+#endif
|
|
|
c5d972 |
|
|
|
c5d972 |
|
|
|
c5d972 |
__fortify_function char *
|