summaryrefslogtreecommitdiff
path: root/debug/swprintf_chk.c
diff options
context:
space:
mode:
Diffstat (limited to 'debug/swprintf_chk.c')
-rw-r--r--debug/swprintf_chk.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/debug/swprintf_chk.c b/debug/swprintf_chk.c
index 35887e48e2..036f5bd6da 100644
--- a/debug/swprintf_chk.c
+++ b/debug/swprintf_chk.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2018 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2019 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
@@ -13,23 +13,30 @@
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/>. */
+ <https://www.gnu.org/licenses/>. */
#include <stdarg.h>
-#include <wchar.h>
+#include <libio/libioP.h>
-/* Write formatted output into S, according to the format string FORMAT. */
-/* VARARGS5 */
+
+/* Write formatted output into S, according to the format string FORMAT,
+ writing no more than MAXLEN characters. */
int
-__swprintf_chk (wchar_t *s, size_t n, int flag, size_t s_len,
+__swprintf_chk (wchar_t *s, size_t maxlen, int flag, size_t slen,
const wchar_t *format, ...)
{
- va_list arg;
- int done;
+ if (__glibc_unlikely (slen < maxlen))
+ __chk_fail ();
+
+ /* For flag > 0 (i.e. __USE_FORTIFY_LEVEL > 1) request that %n
+ can only come from read-only format strings. */
+ unsigned int mode = (flag > 0) ? PRINTF_FORTIFY : 0;
+ va_list ap;
+ int ret;
- va_start (arg, format);
- done = __vswprintf_chk (s, n, flag, s_len, format, arg);
- va_end (arg);
+ va_start (ap, format);
+ ret = __vswprintf_internal (s, maxlen, format, ap, mode);
+ va_end (ap);
- return done;
+ return ret;
}