Use gcc stpncpy chk builtin (BZ #20661)
Commit Message
Since r182378 GCC provides stpncpy_chk builtin support and it is
included in official GCC 4.7.4 package. It allows GLIBC to use it
on string3.h headers without any additional guards.
This patch changes current fortify code to use it instead. The
fortify definition is also new guarded with __USE_GNU, similar to
stpcpy.
Check on x86_64 with GCC 5.4.
[BZ #20661]
* string/bits/string3 [__USE_GNU] (stpncpy): Add fortify version based
on GCC builtin.
---
ChangeLog | 6 ++++++
string/bits/string3.h | 13 ++++---------
2 files changed, 10 insertions(+), 9 deletions(-)
Comments
On Fri, 30 Sep 2016, Adhemerval Zanella wrote:
> Since r182378 GCC provides stpncpy_chk builtin support and it is
> included in official GCC 4.7.4 package. It allows GLIBC to use it
> on string3.h headers without any additional guards.
You'll need to explain this more. The installed glibc headers support GCC
2.7 and later. What is the minimum GCC version for which the installed
headers will end up including <bits/string3.h>? Is it more recent than
the minimum version that has this built-in function?
@@ -38,6 +38,7 @@ __warndecl (__warn_memset_zero_len,
# ifdef __USE_GNU
# undef mempcpy
# undef stpcpy
+# undef stpncpy
# endif
# ifdef __USE_MISC
# undef bcopy
@@ -126,20 +127,14 @@ __NTH (strncpy (char *__restrict __dest, const char *__restrict __src,
return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
}
-/* XXX We have no corresponding builtin yet. */
-extern char *__stpncpy_chk (char *__dest, const char *__src, size_t __n,
- size_t __destlen) __THROW;
-extern char *__REDIRECT_NTH (__stpncpy_alias, (char *__dest, const char *__src,
- size_t __n), stpncpy);
+#ifdef __USE_GNU
__fortify_function char *
__NTH (stpncpy (char *__dest, const char *__src, size_t __n))
{
- if (__bos (__dest) != (size_t) -1
- && (!__builtin_constant_p (__n) || __n > __bos (__dest)))
- return __stpncpy_chk (__dest, __src, __n, __bos (__dest));
- return __stpncpy_alias (__dest, __src, __n);
+ return __builtin___stpncpy_chk (__dest, __src, __n, __bos (__dest));
}
+#endif
__fortify_function char *