From 06febd8c6705c816b2f32ee7aa1f4c0184b05248 Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Mon, 4 May 2020 11:21:50 -0600 Subject: 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 --- libio/bits/stdio2.h | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'libio/bits') diff --git a/libio/bits/stdio2.h b/libio/bits/stdio2.h index 60bc817..ff9202c 100644 --- a/libio/bits/stdio2.h +++ b/libio/bits/stdio2.h @@ -24,10 +24,12 @@ #endif extern int __sprintf_chk (char *__restrict __s, int __flag, size_t __slen, - const char *__restrict __format, ...) __THROW; + const char *__restrict __format, ...) __THROW + __attr_access ((__write_only__, 1, 3)); extern int __vsprintf_chk (char *__restrict __s, int __flag, size_t __slen, const char *__restrict __format, - __gnuc_va_list __ap) __THROW; + __gnuc_va_list __ap) __THROW + __attr_access ((__write_only__, 1, 3)); #ifdef __va_arg_pack __fortify_function int @@ -54,7 +56,8 @@ __NTH (vsprintf (char *__restrict __s, const char *__restrict __fmt, extern int __snprintf_chk (char *__restrict __s, size_t __n, int __flag, size_t __slen, const char *__restrict __format, - ...) __THROW; + ...) __THROW + __attr_access ((__write_only__, 1, 2)); extern int __vsnprintf_chk (char *__restrict __s, size_t __n, int __flag, size_t __slen, const char *__restrict __format, __gnuc_va_list __ap) __THROW; @@ -241,17 +244,19 @@ gets (char *__str) #endif extern char *__fgets_chk (char *__restrict __s, size_t __size, int __n, - FILE *__restrict __stream) __wur; + FILE *__restrict __stream) + __wur __attr_access ((__write_only__, 1, 3)); extern char *__REDIRECT (__fgets_alias, (char *__restrict __s, int __n, - FILE *__restrict __stream), fgets) __wur; + FILE *__restrict __stream), fgets) + __wur __attr_access ((__write_only__, 1, 2)); extern char *__REDIRECT (__fgets_chk_warn, (char *__restrict __s, size_t __size, int __n, FILE *__restrict __stream), __fgets_chk) __wur __warnattr ("fgets called with bigger size than length " "of destination buffer"); -__fortify_function __wur char * +__fortify_function __wur __attr_access ((__write_only__, 1, 2)) char * fgets (char *__restrict __s, int __n, FILE *__restrict __stream) { if (__bos (__s) != (size_t) -1) @@ -299,17 +304,19 @@ fread (void *__restrict __ptr, size_t __size, size_t __n, #ifdef __USE_GNU extern char *__fgets_unlocked_chk (char *__restrict __s, size_t __size, - int __n, FILE *__restrict __stream) __wur; + int __n, FILE *__restrict __stream) + __wur __attr_access ((__write_only__, 1, 3)); extern char *__REDIRECT (__fgets_unlocked_alias, (char *__restrict __s, int __n, - FILE *__restrict __stream), fgets_unlocked) __wur; + FILE *__restrict __stream), fgets_unlocked) + __wur __attr_access ((__write_only__, 1, 2)); extern char *__REDIRECT (__fgets_unlocked_chk_warn, (char *__restrict __s, size_t __size, int __n, FILE *__restrict __stream), __fgets_unlocked_chk) __wur __warnattr ("fgets_unlocked called with bigger size than length " "of destination buffer"); -__fortify_function __wur char * +__fortify_function __wur __attr_access ((__write_only__, 1, 2)) char * fgets_unlocked (char *__restrict __s, int __n, FILE *__restrict __stream) { if (__bos (__s) != (size_t) -1) -- cgit v1.1