Signed-off-by: Waldemar Kozaczuk <[email protected]>
---
 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

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osv-dev/20220520193257.146906-1-jwkozaczuk%40gmail.com.

Reply via email to