@@ -215,6 +215,7 @@ tests := \
tst-openat \
tst-posix_fallocate \
tst-posix_fallocate64 \
+ tst-read-zero \
tst-readlinkat \
tst-renameat \
tst-stat \
new file mode 100644
@@ -0,0 +1,35 @@
+/* read smoke test for 0-sized structures.
+ Copyright The GNU Toolchain Authors.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+/* Zero-sized structures should not result in any overflow warnings or
+ errors when fortification is enabled. */
+#define _FORTIFY_SOURCE 3
+#include <stdio.h>
+#include <unistd.h>
+#include <support/check.h>
+
+int
+do_test (void)
+{
+ struct test_st {} test_info[16];
+
+ TEST_VERIFY_EXIT (read (0, test_info, sizeof(test_info)) == 0);
+ return 0;
+}
+
+#include <support/test-driver.c>
@@ -683,10 +683,10 @@ _Static_assert (0, "IEEE 128-bits long double requires redirection on this platf
# define __attr_access(x) __attribute__ ((__access__ x))
/* For _FORTIFY_SOURCE == 3 we use __builtin_dynamic_object_size, which may
use the access attribute to get object sizes from function definition
- arguments, so we can't use them on functions we fortify. Drop the object
- size hints for such functions. */
+ arguments, so we can't use them on functions we fortify. Drop the access
+ attribute for such functions. */
# if __USE_FORTIFY_LEVEL == 3
-# define __fortified_attr_access(a, o, s) __attribute__ ((__access__ (a, o)))
+# define __fortified_attr_access(a, o, s)
# else
# define __fortified_attr_access(a, o, s) __attr_access ((a, o, s))
# endif
When passed a pointer to a zero-sized struct, the access attribute without the third argument misleads -Wstringop-overflow diagnostics to think that a function is writing 1 byte into the zero-sized structs. The attribute doesn't add that much value in this context, so drop it completely for _FORTIFY_SOURCE=3. Resolves: BZ #31383 Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org> --- Tested on x86_64 io/Makefile | 1 + io/tst-read-zero.c | 35 +++++++++++++++++++++++++++++++++++ misc/sys/cdefs.h | 6 +++--- 3 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 io/tst-read-zero.c