From c820eed56f8e30a524050d8f91148decfea1ec9b Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Tue, 7 May 2019 20:02:39 -0500 Subject: wchar: Add __wcscpy_chk --- CHANGELOG.rst | 5 +++++ libgcompat/wchar.c | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 5a17069..a4d7698 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -11,6 +11,11 @@ 1.0.0 (20??-??-??) ================== +wchar +----- + +* Add __wcscpy_chk. + 0.4.0 (2019-05-03) ================== diff --git a/libgcompat/wchar.c b/libgcompat/wchar.c index c60963e..1a5a23c 100644 --- a/libgcompat/wchar.c +++ b/libgcompat/wchar.c @@ -39,6 +39,27 @@ int __vswprintf_chk(wchar_t *s, size_t n, int flag, size_t slen, return vswprintf(s, n, format, ap); } +/** + * Copy a wide-character string, with buffer overflow checking + * + * LSB 5.0: LSB-Core-generic/baselib---wcscpy-chk-1.html + */ +wchar_t *__wcscpy_chk(wchar_t *dest, const wchar_t *src, size_t n) +{ + size_t srclen = wcslen(src) + 1; + + assert(dest != NULL); + assert(src != NULL); + assert(n >= srclen); + if (dest < src) { + assert(dest + n <= src); + } else { + assert(src + n <= dest); + } + + return wcscpy(dest, src); +} + /** * Representation of the glibc internals of wcstol(3). * -- cgit v1.2.3-70-g09d2