This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Use gcc stpncpy chk builtin (BZ #20661)


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(-)

diff --git a/string/bits/string3.h b/string/bits/string3.h
index 8f13b65..e19947c 100644
--- a/string/bits/string3.h
+++ b/string/bits/string3.h
@@ -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 *
-- 
2.7.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]