public inbox for newlib-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin] ssp: add Object Size Checking for wchar.h, part 1
@ 2017-12-04 10:14 Yaakov Selkowitz
0 siblings, 0 replies; only message in thread
From: Yaakov Selkowitz @ 2017-12-04 10:14 UTC (permalink / raw)
To: newlib-cvs
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=8f7c712bb8db2a811bf8b8c6628d4f83a2118cc7
commit 8f7c712bb8db2a811bf8b8c6628d4f83a2118cc7
Author: Yaakov Selkowitz <yselkowi@redhat.com>
Date: Fri Dec 1 12:45:14 2017 -0600
ssp: add Object Size Checking for wchar.h, part 1
The following functions are also guarded in glibc:
fwprintf, swprintf, wprintf, vfwprintf, vswprintf, vwprintf.
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
Diff:
---
newlib/libc/include/ssp/wchar.h | 97 +++++++++++++++++++++++++++++++++++++++++
newlib/libc/include/wchar.h | 4 ++
newlib/libc/ssp/ssp.tex | 8 ++++
3 files changed, 109 insertions(+)
diff --git a/newlib/libc/include/ssp/wchar.h b/newlib/libc/include/ssp/wchar.h
new file mode 100644
index 0000000..39033cf
--- /dev/null
+++ b/newlib/libc/include/ssp/wchar.h
@@ -0,0 +1,97 @@
+#ifndef _SSP_WCHAR_H_
+#define _SSP_WCHAR_H_
+
+#include <sys/cdefs.h>
+#include <ssp/ssp.h>
+
+#if __SSP_FORTIFY_LEVEL > 0
+
+/* wide character variant, __wlen is number of wchar_t */
+#define __ssp_redirect_wc(rtype, fun, args, call, cond, bos) \
+__ssp_decl(rtype, fun, args) \
+{ \
+ if (cond) \
+ __ssp_check(__buf, __wlen * sizeof(wchar_t), bos); \
+ return __ssp_real_(fun) call; \
+}
+
+#define __ssp_bos_wicheck3(fun) \
+__ssp_redirect_wc(wchar_t *, fun, \
+ (wchar_t *__buf, const wchar_t *__src, size_t __wlen), \
+ (__buf, __src, __wlen), 1, __ssp_bos0)
+
+#define __ssp_bos_wicheck3_restrict(fun) \
+__ssp_redirect_wc(wchar_t *, fun, \
+ (wchar_t *__restrict __buf, const wchar_t *__restrict __src, size_t __wlen), \
+ (__buf, __src, __wlen), 1, __ssp_bos0)
+
+#define __ssp_bos_wicheck2_restrict(fun) \
+__ssp_decl(wchar_t *, fun, (wchar_t *__restrict __buf, const wchar_t *__restrict __src)) \
+{ \
+ __ssp_check(__buf, (wcslen(__src) + 1) * sizeof(wchar_t), __ssp_bos0); \
+ return __ssp_real_(fun) (__buf, __src); \
+}
+
+__BEGIN_DECLS
+#if __POSIX_VISIBLE >= 200809
+__ssp_bos_wicheck2_restrict(wcpcpy)
+__ssp_bos_wicheck3_restrict(wcpncpy)
+#endif
+__ssp_bos_wicheck2_restrict(wcscpy)
+__ssp_bos_wicheck2_restrict(wcscat)
+__ssp_bos_wicheck3_restrict(wcsncpy)
+__ssp_bos_wicheck3_restrict(wcsncat)
+__ssp_bos_wicheck3_restrict(wmemcpy)
+__ssp_bos_wicheck3(wmemmove)
+#if __GNU_VISIBLE
+__ssp_bos_wicheck3_restrict(wmempcpy)
+#endif
+__ssp_redirect_wc(wchar_t *, wmemset, \
+ (wchar_t *__buf, wchar_t __src, size_t __wlen), \
+ (__buf, __src, __wlen), 1, __ssp_bos0)
+
+__ssp_decl(size_t, wcrtomb, (char *__buf, wchar_t __src, mbstate_t *__ps))
+{
+ if (__buf != NULL && __src != L'\0')
+ __ssp_check(__buf, sizeof(wchar_t), __ssp_bos);
+ return __ssp_real_wcrtomb (__buf, __src, __ps);
+}
+
+__ssp_redirect_wc(size_t, mbsrtowcs, \
+ (wchar_t *__buf, const char **__src, size_t __wlen, mbstate_t *__ps), \
+ (__buf, __src, __wlen, __ps), __buf != NULL, __ssp_bos)
+
+__ssp_redirect_raw(size_t, wcsrtombs, \
+ (char *__buf, const wchar_t **__src, size_t __len, mbstate_t *__ps), \
+ (__buf, __src, __len, __ps), __buf != NULL, __ssp_bos)
+
+#if __POSIX_VISIBLE >= 200809
+__ssp_redirect_wc(size_t, mbsnrtowcs, \
+ (wchar_t *__buf, const char **__src, size_t __nms, size_t __wlen, mbstate_t *__ps), \
+ (__buf, __src, __nms, __wlen, __ps), __buf != NULL, __ssp_bos)
+
+__ssp_redirect_raw(size_t, wcsnrtombs, \
+ (char *__buf, const wchar_t **__src, size_t __nwc, size_t __len, mbstate_t *__ps), \
+ (__buf, __src, __nwc, __len, __ps), __buf != NULL, __ssp_bos)
+#endif
+
+__ssp_decl(wchar_t *, fgetws, (wchar_t *__restrict __buf, int __wlen, FILE *__restrict __fp))
+{
+ if (__wlen > 0)
+ __ssp_check(__buf, (size_t)__wlen * sizeof(wchar_t) , __ssp_bos);
+ return __ssp_real_fgetws(__buf, __wlen, __fp);
+}
+
+#if __GNU_VISIBLE
+__ssp_decl(wchar_t *, fgetws_unlocked, (wchar_t *__buf, int __wlen, FILE *__fp))
+{
+ if (__wlen > 0)
+ __ssp_check(__buf, (size_t)__wlen * sizeof(wchar_t) , __ssp_bos);
+ return __ssp_real_fgetws_unlocked(__buf, __wlen, __fp);
+}
+#endif /* __GNU_VISIBLE */
+
+__END_DECLS
+
+#endif /* __SSP_FORTIFY_LEVEL > 0 */
+#endif /* _SSP_WCHAR_H_ */
diff --git a/newlib/libc/include/wchar.h b/newlib/libc/include/wchar.h
index 16e28f4..dccc106 100644
--- a/newlib/libc/include/wchar.h
+++ b/newlib/libc/include/wchar.h
@@ -332,4 +332,8 @@ int _EXFUN(_wscanf_r, (struct _reent *, const wchar_t *, ...));
_END_STD_C
+#if __SSP_FORTIFY_LEVEL > 0
+#include <ssp/wchar.h>
+#endif
+
#endif /* _WCHAR_H_ */
diff --git a/newlib/libc/ssp/ssp.tex b/newlib/libc/ssp/ssp.tex
index 1e0cb6b..9270350 100644
--- a/newlib/libc/ssp/ssp.tex
+++ b/newlib/libc/ssp/ssp.tex
@@ -34,6 +34,14 @@ bzero mempcpy strcat
explicit_bzero memset strncat
memcpy stpcpy strncpy
+@exdent @emph{Wide Character String functions:}
+fgetws wcrtomb wcsrtombs
+fgetws_unlocked wcscat wmemcpy
+mbsnrtowcs wcscpy wmemmove
+mbsrtowcs wcsncat wmempcpy
+wcpcpy wcsncpy wmemset
+wcpncpy wcsnrtombs
+
@exdent @emph{Stdio functions:}
fgets fread_unlocked sprintf
fgets_unlocked gets vsnprintf
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2017-12-04 10:14 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-04 10:14 [newlib-cygwin] ssp: add Object Size Checking for wchar.h, part 1 Yaakov Selkowitz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).