[PATCH] debug: Fix missing fortify checks in nldbl compat wrappers (bug 34529)

Florian Weimer <[email protected]>
Newsgroups gmane.comp.lib.glibc.alpha
Message-ID <[email protected]>
Re-use debug/tst-fortify to exercise at least some of the build
variants.

---
 sysdeps/ieee754/ldbl-opt/Makefile              | 18 ++++++++++++++++++
 sysdeps/ieee754/ldbl-opt/nldbl-compat.c        |  8 ++++++++
 sysdeps/ieee754/ldbl-opt/tst-nldbl-fortify-1.c |  1 +
 sysdeps/ieee754/ldbl-opt/tst-nldbl-fortify-2.c |  1 +
 4 files changed, 28 insertions(+)

diff --git a/sysdeps/ieee754/ldbl-opt/Makefile b/sysdeps/ieee754/ldbl-opt/Makefile
index ef7da1f830..de5bec0272 100644
--- a/sysdeps/ieee754/ldbl-opt/Makefile
+++ b/sysdeps/ieee754/ldbl-opt/Makefile
@@ -555,6 +555,24 @@ CFLAGS-tst-nldbl-wscanf-binary-gnu89.c += -mlong-double-64 -std=gnu89 \
 
 endif
 
+ifeq ($(subdir), debug)
+tests += \
+  tst-nldbl-fortify-1 \
+  tst-nldbl-fortify-2
+  # tests
+
+CFLAGS-tst-nldbl-fortify-1.c += -mlong-double-64 \
+  $(no-fortify-source) -D_FORTIFY_SOURCE=1 \
+  -Wno-format -Wno-deprecated-declarations -Wno-error
+
+CFLAGS-tst-nldbl-fortify-2.c += -mlong-double-64 \
+  $(no-fortify-source) -D_FORTIFY_SOURCE=2 \
+  -Wno-format -Wno-deprecated-declarations -Wno-error
+
+$(objpfx)tst-nldbl-fortify-1: $(common-objpfx)math/libnldbl_nonshared.a
+$(objpfx)tst-nldbl-fortify-2: $(common-objpfx)math/libnldbl_nonshared.a
+endif # $(subdir) == debug
+
 routines_no_fortify += \
   nldbl-asprintf \
   nldbl-dprintf \
diff --git a/sysdeps/ieee754/ldbl-opt/nldbl-compat.c b/sysdeps/ieee754/ldbl-opt/nldbl-compat.c
index e239cd5bc5..4bc21f875c 100644
--- a/sysdeps/ieee754/ldbl-opt/nldbl-compat.c
+++ b/sysdeps/ieee754/ldbl-opt/nldbl-compat.c
@@ -517,6 +517,10 @@ __nldbl___sprintf_chk (char *s, int flag, size_t slen, const char *fmt, ...)
   if (flag > 0)
     mode |= PRINTF_FORTIFY;
 
+  /* Regardless of the value of flag, let __vsprintf_internal know
+     that this is a call from *printf_chk.  */
+  mode |= PRINTF_CHK;
+
   va_start (ap, fmt);
   ret = __vsprintf_internal (s, slen, fmt, ap, mode);
   va_end (ap);
@@ -605,6 +609,10 @@ __nldbl___vsprintf_chk (char *string, int flag, size_t slen, const char *fmt,
   if (flag > 0)
     mode |= PRINTF_FORTIFY;
 
+  /* Regardless of the value of flag, let __vsprintf_internal know
+     that this is a call from *printf_chk.  */
+  mode |= PRINTF_CHK;
+
   return __vsprintf_internal (string, slen, fmt, ap, mode);
 }
 
diff --git a/sysdeps/ieee754/ldbl-opt/tst-nldbl-fortify-1.c b/sysdeps/ieee754/ldbl-opt/tst-nldbl-fortify-1.c
new file mode 100644
index 0000000000..90269ec6d9
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-opt/tst-nldbl-fortify-1.c
@@ -0,0 +1 @@
+#include <debug/tst-fortify.c>
diff --git a/sysdeps/ieee754/ldbl-opt/tst-nldbl-fortify-2.c b/sysdeps/ieee754/ldbl-opt/tst-nldbl-fortify-2.c
new file mode 100644
index 0000000000..90269ec6d9
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-opt/tst-nldbl-fortify-2.c
@@ -0,0 +1 @@
+#include <debug/tst-fortify.c>

base-commit: 6144ef08960e1db191db2054abef02d361042018
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.