This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH v3 6/7] Use PRINTF_FORTIFY instead of _IO_FLAGS2_FORTIFY (bug 11319)
- From: "Gabriel F. T. Gomes" <gabriel at inconstante dot eti dot br>
- To: Adhemerval Zanella <adhemerval dot zanella at linaro dot org>
- Cc: <libc-alpha at sourceware dot org>
- Date: Tue, 4 Dec 2018 16:01:27 -0200
- Subject: Re: [PATCH v3 6/7] Use PRINTF_FORTIFY instead of _IO_FLAGS2_FORTIFY (bug 11319)
- References: <20181115214449.19262-1-gabriel@inconstante.eti.br> <20181115214449.19262-7-gabriel@inconstante.eti.br> <878aa68c-1a30-69d6-ae01-4acd6d80ccaa@linaro.org> <20181204141946.26ba9107@tereshkova> <4eff527e-f466-d778-bc14-00727be3e1b1@linaro.org>
On Tue, 04 Dec 2018, Adhemerval Zanella wrote:
>Thanks for confirm it, could you attach the add the testcase as well?
>I would prefer to push along with the patch itself, and there is no need
>to send a new version for the whole set. Just update this one.
This is the patch (I hope my email client doesn't screw it)...
From a583fded669048e7d58c760810e30758a5ede286 Mon Sep 17 00:00:00 2001
From: "Gabriel F. T. Gomes" <gabriel@inconstante.eti.br>
Date: Tue, 4 Dec 2018 15:57:57 -0200
Subject: [PATCH] Add test for bug 11319
The commit
commit 7ca890b88e6ab7624afb1742a9fffb37ad5b3fc3
Author: Ulrich Drepper <drepper@redhat.com>
Date: Wed Feb 24 16:07:57 2010 -0800
Fix reporting of I/O errors in *dprintf functions.
fixed bug 11319 for dprintf and vdprintf, however, it did not fix it for
__dprintf_chk and __vdprintf_chk. As a side-effect of the refactoring
of libio functions, this bug is also fixed for the foritified functions.
This patch adds a test case to avoid regressions.
Tested for powerpc64le and x86_64.
* stdio-common/Makefile (tests): Add tst-bz11319 and
tst-bz11319-fortify2.
(CFLAGS-tst-bz11319-fortify2.c): New macro.
* stdio-common/tst-bz11319-fortify2.c: New file.
* stdio-common/tst-bz11319.c: Likewise.
---
stdio-common/Makefile | 6 ++++-
stdio-common/tst-bz11319-fortify2.c | 1 +
stdio-common/tst-bz11319.c | 48 +++++++++++++++++++++++++++++++++++++
3 files changed, 54 insertions(+), 1 deletion(-)
create mode 100644 stdio-common/tst-bz11319-fortify2.c
create mode 100644 stdio-common/tst-bz11319.c
diff --git a/stdio-common/Makefile b/stdio-common/Makefile
index 84bad1fafe..8978b3fb1f 100644
--- a/stdio-common/Makefile
+++ b/stdio-common/Makefile
@@ -64,7 +64,7 @@ tests := tstscanf test_rdwr test-popen tstgetln test-fseek \
tst-vfprintf-user-type \
tst-vfprintf-mbs-prec \
tst-scanf-round \
- tst-renameat2 \
+ tst-renameat2 tst-bz11319 tst-bz11319-fortify2 \
test-srcs = tst-unbputc tst-printf tst-printfsz-islongdouble
@@ -164,6 +164,10 @@ CFLAGS-test_rdwr.c += -DOBJPFX=\"$(objpfx)\"
# tst-gets.c tests a deprecated function.
CFLAGS-tst-gets.c += -Wno-deprecated-declarations
+# BZ #11319 was first fixed for regular vdprintf, then reopened because
+# the fortified version had the same bug.
+CFLAGS-tst-bz11319-fortify2.c += -D_FORTIFY_SOURCE=2
+
CPPFLAGS += $(libio-mtsafe)
$(objpfx)tst-setvbuf1.out: /dev/null $(objpfx)tst-setvbuf1
diff --git a/stdio-common/tst-bz11319-fortify2.c b/stdio-common/tst-bz11319-fortify2.c
new file mode 100644
index 0000000000..a8df9a39bd
--- /dev/null
+++ b/stdio-common/tst-bz11319-fortify2.c
@@ -0,0 +1 @@
+#include <tst-bz11319.c>
diff --git a/stdio-common/tst-bz11319.c b/stdio-common/tst-bz11319.c
new file mode 100644
index 0000000000..ce2dee13ae
--- /dev/null
+++ b/stdio-common/tst-bz11319.c
@@ -0,0 +1,48 @@
+/* Regression test for bug 11319.
+ Copyright (C) 2018 Free Software Foundation, Inc.
+ 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
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE 1
+#endif
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/eventfd.h>
+
+#include <support/check.h>
+
+static int
+do_test (void)
+{
+ int ret;
+ int fd = eventfd(0, 0);
+
+ /* man 2 eventfd:
+
+ A write(2) will fail with the error EINVAL if the size of the
+ supplied buffer is less than 8 bytes... */
+ ret = dprintf(fd, "%d", 0);
+
+ TEST_VERIFY (ret < 0);
+ TEST_COMPARE (errno, EINVAL);
+
+ return 0;
+}
+
+#include <support/test-driver.c>
--
2.14.5
>From a583fded669048e7d58c760810e30758a5ede286 Mon Sep 17 00:00:00 2001
From: "Gabriel F. T. Gomes" <gabriel@inconstante.eti.br>
Date: Tue, 4 Dec 2018 15:57:57 -0200
Subject: [PATCH] Add test for bug 11319
The commit
commit 7ca890b88e6ab7624afb1742a9fffb37ad5b3fc3
Author: Ulrich Drepper <drepper@redhat.com>
Date: Wed Feb 24 16:07:57 2010 -0800
Fix reporting of I/O errors in *dprintf functions.
fixed bug 11319 for dprintf and vdprintf, however, it did not fix it for
__dprintf_chk and __vdprintf_chk. As a side-effect of the refactoring
of libio functions, this bug is also fixed for the foritified functions.
This patch adds a test case to avoid regressions.
Tested for powerpc64le and x86_64.
* stdio-common/Makefile (tests): Add tst-bz11319 and
tst-bz11319-fortify2.
(CFLAGS-tst-bz11319-fortify2.c): New macro.
* stdio-common/tst-bz11319-fortify2.c: New file.
* stdio-common/tst-bz11319.c: Likewise.
---
stdio-common/Makefile | 6 ++++-
stdio-common/tst-bz11319-fortify2.c | 1 +
stdio-common/tst-bz11319.c | 48 +++++++++++++++++++++++++++++++++++++
3 files changed, 54 insertions(+), 1 deletion(-)
create mode 100644 stdio-common/tst-bz11319-fortify2.c
create mode 100644 stdio-common/tst-bz11319.c
diff --git a/stdio-common/Makefile b/stdio-common/Makefile
index 84bad1fafe..8978b3fb1f 100644
--- a/stdio-common/Makefile
+++ b/stdio-common/Makefile
@@ -64,7 +64,7 @@ tests := tstscanf test_rdwr test-popen tstgetln test-fseek \
tst-vfprintf-user-type \
tst-vfprintf-mbs-prec \
tst-scanf-round \
- tst-renameat2 \
+ tst-renameat2 tst-bz11319 tst-bz11319-fortify2 \
test-srcs = tst-unbputc tst-printf tst-printfsz-islongdouble
@@ -164,6 +164,10 @@ CFLAGS-test_rdwr.c += -DOBJPFX=\"$(objpfx)\"
# tst-gets.c tests a deprecated function.
CFLAGS-tst-gets.c += -Wno-deprecated-declarations
+# BZ #11319 was first fixed for regular vdprintf, then reopened because
+# the fortified version had the same bug.
+CFLAGS-tst-bz11319-fortify2.c += -D_FORTIFY_SOURCE=2
+
CPPFLAGS += $(libio-mtsafe)
$(objpfx)tst-setvbuf1.out: /dev/null $(objpfx)tst-setvbuf1
diff --git a/stdio-common/tst-bz11319-fortify2.c b/stdio-common/tst-bz11319-fortify2.c
new file mode 100644
index 0000000000..a8df9a39bd
--- /dev/null
+++ b/stdio-common/tst-bz11319-fortify2.c
@@ -0,0 +1 @@
+#include <tst-bz11319.c>
diff --git a/stdio-common/tst-bz11319.c b/stdio-common/tst-bz11319.c
new file mode 100644
index 0000000000..ce2dee13ae
--- /dev/null
+++ b/stdio-common/tst-bz11319.c
@@ -0,0 +1,48 @@
+/* Regression test for bug 11319.
+ Copyright (C) 2018 Free Software Foundation, Inc.
+ 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
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE 1
+#endif
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/eventfd.h>
+
+#include <support/check.h>
+
+static int
+do_test (void)
+{
+ int ret;
+ int fd = eventfd(0, 0);
+
+ /* man 2 eventfd:
+
+ A write(2) will fail with the error EINVAL if the size of the
+ supplied buffer is less than 8 bytes... */
+ ret = dprintf(fd, "%d", 0);
+
+ TEST_VERIFY (ret < 0);
+ TEST_COMPARE (errno, EINVAL);
+
+ return 0;
+}
+
+#include <support/test-driver.c>
--
2.14.5