Signed-off-by: Waldemar Kozaczuk <
jwkoz...@gmail.com>
---
Makefile | 1 +
libc/multibyte/__mbstowcs_chk.c | 17 +++++++++++++++++
2 files changed, 18 insertions(+)
create mode 100644 libc/multibyte/__mbstowcs_chk.c
diff --git a/Makefile b/Makefile
index 3e87a16d..19a4571b 100644
--- a/Makefile
+++ b/Makefile
@@ -1451,6 +1451,7 @@ libc += multibyte/__mbsnrtowcs_chk.o
musl += multibyte/mbsrtowcs.o
libc += multibyte/__mbsrtowcs_chk.o
musl += multibyte/mbstowcs.o
+libc += multibyte/__mbstowcs_chk.o
musl += multibyte/mbtowc.o
musl += multibyte/wcrtomb.o
musl += multibyte/wcsnrtombs.o
diff --git a/libc/multibyte/__mbstowcs_chk.c b/libc/multibyte/__mbstowcs_chk.c
new file mode 100644
index 00000000..fcc390df
--- /dev/null
+++ b/libc/multibyte/__mbstowcs_chk.c
@@ -0,0 +1,17 @@
+/*
+ * Copyright (C) 2022 Waldemar Kozaczuk
+ *
+ * This work is open source software, licensed under the terms of the
+ * BSD license as described in the LICENSE file in the top-level directory.
+ */
+
+#include <wchar.h>
+#include <libc/internal/libc.h>
+
+size_t __mbstowcs_chk(wchar_t *restrict dest, const char *restrict src, size_t n, size_t dstlen)
+{
+ if (n > dstlen) {
+ _chk_fail("mbstowcs");
+ }
+ return mbstowcs(dest, src, n);
+}
--
2.34.1