about summary refs log tree commit diff
path: root/stdlib
diff options
context:
space:
mode:
authorMartin Sebor <msebor@redhat.com>2020-05-04 11:21:50 -0600
committerMartin Sebor <msebor@redhat.com>2020-05-04 11:21:50 -0600
commit06febd8c6705c816b2f32ee7aa1f4c0184b05248 (patch)
tree71586b8485abc1c6b220cb6aba340e76286b3087 /stdlib
parent38c67888183db1b6ac21f2f9681b8a384987dfe8 (diff)
downloadglibc-06febd8c6705c816b2f32ee7aa1f4c0184b05248.tar.gz
glibc-06febd8c6705c816b2f32ee7aa1f4c0184b05248.tar.xz
glibc-06febd8c6705c816b2f32ee7aa1f4c0184b05248.zip
improve out-of-bounds checking with GCC 10 attribute access [BZ #25219]
Adds the access attribute newly introduced in GCC 10 to the subset of
function declarations that are already covered by _FORTIFY_SOURCE and
that don't have corresponding GCC built-in equivalents.

Reviewed-by: DJ Delorie <dj@redhat.com>
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/bits/stdlib.h17
-rw-r--r--stdlib/stdlib.h9
2 files changed, 16 insertions, 10 deletions
diff --git a/stdlib/bits/stdlib.h b/stdlib/bits/stdlib.h
index bfdee75073..9134d3f36b 100644
--- a/stdlib/bits/stdlib.h
+++ b/stdlib/bits/stdlib.h
@@ -50,10 +50,11 @@ __NTH (realpath (const char *__restrict __name, char *__restrict __resolved))
 
 
 extern int __ptsname_r_chk (int __fd, char *__buf, size_t __buflen,
-			    size_t __nreal) __THROW __nonnull ((2));
+			    size_t __nreal) __THROW __nonnull ((2))
+    __attr_access ((__write_only__, 2, 3));
 extern int __REDIRECT_NTH (__ptsname_r_alias, (int __fd, char *__buf,
 					       size_t __buflen), ptsname_r)
-     __nonnull ((2));
+     __nonnull ((2)) __attr_access ((__write_only__, 2, 3));
 extern int __REDIRECT_NTH (__ptsname_r_chk_warn,
 			   (int __fd, char *__buf, size_t __buflen,
 			    size_t __nreal), __ptsname_r_chk)
@@ -97,11 +98,13 @@ __NTH (wctomb (char *__s, wchar_t __wchar))
 
 extern size_t __mbstowcs_chk (wchar_t *__restrict __dst,
 			      const char *__restrict __src,
-			      size_t __len, size_t __dstlen) __THROW;
+			      size_t __len, size_t __dstlen) __THROW
+    __attr_access ((__write_only__, 1, 3)) __attr_access ((__read_only__, 2));
 extern size_t __REDIRECT_NTH (__mbstowcs_alias,
 			      (wchar_t *__restrict __dst,
 			       const char *__restrict __src,
-			       size_t __len), mbstowcs);
+			       size_t __len), mbstowcs)
+    __attr_access ((__write_only__, 1, 3)) __attr_access ((__read_only__, 2));
 extern size_t __REDIRECT_NTH (__mbstowcs_chk_warn,
 			      (wchar_t *__restrict __dst,
 			       const char *__restrict __src,
@@ -129,11 +132,13 @@ __NTH (mbstowcs (wchar_t *__restrict __dst, const char *__restrict __src,
 
 extern size_t __wcstombs_chk (char *__restrict __dst,
 			      const wchar_t *__restrict __src,
-			      size_t __len, size_t __dstlen) __THROW;
+			      size_t __len, size_t __dstlen) __THROW
+  __attr_access ((__write_only__, 1, 3)) __attr_access ((__read_only__, 2));
 extern size_t __REDIRECT_NTH (__wcstombs_alias,
 			      (char *__restrict __dst,
 			       const wchar_t *__restrict __src,
-			       size_t __len), wcstombs);
+			       size_t __len), wcstombs)
+  __attr_access ((__write_only__, 1, 3)) __attr_access ((__read_only__, 2));
 extern size_t __REDIRECT_NTH (__wcstombs_chk_warn,
 			      (char *__restrict __dst,
 			       const wchar_t *__restrict __src,
diff --git a/stdlib/stdlib.h b/stdlib/stdlib.h
index 9b7537c545..dd779bd740 100644
--- a/stdlib/stdlib.h
+++ b/stdlib/stdlib.h
@@ -931,12 +931,13 @@ extern int wctomb (char *__s, wchar_t __wchar) __THROW;
 
 /* Convert a multibyte string to a wide char string.  */
 extern size_t mbstowcs (wchar_t *__restrict  __pwcs,
-			const char *__restrict __s, size_t __n) __THROW;
+			const char *__restrict __s, size_t __n) __THROW
+    __attr_access ((__write_only__, 1, 3)) __attr_access ((__read_only__, 2));
 /* Convert a wide char string to multibyte string.  */
 extern size_t wcstombs (char *__restrict __s,
 			const wchar_t *__restrict __pwcs, size_t __n)
-     __THROW;
-
+     __THROW
+  __attr_access ((__write_only__, 1, 3)) __attr_access ((__read_only__, 2));
 
 #ifdef __USE_MISC
 /* Determine whether the string value of RESPONSE matches the affirmation
@@ -990,7 +991,7 @@ extern char *ptsname (int __fd) __THROW __wur;
    terminal associated with the master FD is open on in BUF.
    Return 0 on success, otherwise an error number.  */
 extern int ptsname_r (int __fd, char *__buf, size_t __buflen)
-     __THROW __nonnull ((2));
+     __THROW __nonnull ((2)) __attr_access ((__write_only__, 2, 3));
 
 /* Open a master pseudo terminal and return its file descriptor.  */
 extern int getpt (void);