aboutsummaryrefslogtreecommitdiff
path: root/debug/swprintf_chk.c
diff options
context:
space:
mode:
Diffstat (limited to 'debug/swprintf_chk.c')
-rw-r--r--debug/swprintf_chk.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/debug/swprintf_chk.c b/debug/swprintf_chk.c
index 35887e48e2..186c17751c 100644
--- a/debug/swprintf_chk.c
+++ b/debug/swprintf_chk.c
@@ -16,20 +16,27 @@
<http://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;
}