fortify-headers

standalone fortify-source implementation
git clone git://git.2f30.org/fortify-headers
Log | Files | Refs | README | LICENSE

commit d9feee06053d1f3c006de00b00dd5feb54ca75e5
parent 81527127a9ea5e7db973329b59a5ef7234b05d26
Author: jvoisin <julien.voisin@dustri.org>
Date:   Mon, 21 Aug 2023 00:43:30 +0200

Add tests for fgetws and mbsrtowcs

Diffstat:
Minclude/wchar.h | 2+-
Mtests/Makefile | 4++++
Atests/test_fgetws_dynamic.c | 15+++++++++++++++
Atests/test_fgetws_static.c | 15+++++++++++++++
Atests/test_mbsrtowcs_dynamic.c | 16++++++++++++++++
Atests/test_mbsrtowcs_static.c | 16++++++++++++++++
6 files changed, 67 insertions(+), 1 deletion(-)

diff --git a/include/wchar.h b/include/wchar.h @@ -229,7 +229,7 @@ _FORTIFY_FN(wcsrtombs) size_t wcsrtombs(char * _FORTIFY_POS0 __d, return __r; } -__access(write_only, 2, 3) +__access(write_only, 1, 3) __diagnose_as_builtin(__builtin_wcstombs, 1, 2, 3) _FORTIFY_FN(wcstombs) size_t wcstombs(char * _FORTIFY_POS0 __s, const wchar_t *__ws, size_t __n) diff --git a/tests/Makefile b/tests/Makefile @@ -15,6 +15,8 @@ TARGETS= \ test_confstr_static \ test_fgets_dynamic \ test_fgets_static \ + test_fgetws_dynamic \ + test_fgetws_static \ test_fread_int_overflow \ test_fread_overwrite_dynamic \ test_fread_overwrite_static \ @@ -31,6 +33,8 @@ TARGETS= \ test_gethostname_static \ test_getlogin_r_dynamic \ test_getlogin_r_static \ + test_mbsrtowcs_dynamic \ + test_mbsrtowcs_static \ test_memchr_dynamic_read \ test_memchr_static_read \ test_memcpy_dynamic_read \ diff --git a/tests/test_fgetws_dynamic.c b/tests/test_fgetws_dynamic.c @@ -0,0 +1,15 @@ +#include "common.h" + +#define _GNU_SOURCE +#include <wchar.h> + +int main(int argc, char** argv) { + wchar_t buffer[8] = {L'A'}; + + CHK_FAIL_START + fgetws(buffer, argc, NULL); + CHK_FAIL_END + + putwchar(buffer[0]); + return ret; +} diff --git a/tests/test_fgetws_static.c b/tests/test_fgetws_static.c @@ -0,0 +1,15 @@ +#include "common.h" + +#define _GNU_SOURCE +#include <wchar.h> + +int main(int argc, char** argv) { + wchar_t buffer[12] = {L'A'}; + + CHK_FAIL_START + fgetws(buffer, 14, NULL); + CHK_FAIL_END + + putwchar(buffer[0]); + return ret; +} diff --git a/tests/test_mbsrtowcs_dynamic.c b/tests/test_mbsrtowcs_dynamic.c @@ -0,0 +1,16 @@ +#include "common.h" + +#define _GNU_SOURCE +#include <wchar.h> + +int main(int argc, char** argv) { + wchar_t dest[3]; + const char* src = "abcdefghijklmnopq"; + mbstate_t ps; + + CHK_FAIL_START + mbsrtowcs(dest, &src, argc, &ps); + CHK_FAIL_END + + return ret; +} diff --git a/tests/test_mbsrtowcs_static.c b/tests/test_mbsrtowcs_static.c @@ -0,0 +1,16 @@ +#include "common.h" + +#define _GNU_SOURCE +#include <wchar.h> + +int main(int argc, char** argv) { + wchar_t dest[3]; + const char* src = "abcdefghijklmnopq"; + mbstate_t ps; + + CHK_FAIL_START + mbsrtowcs(dest, &src, 12, &ps); + CHK_FAIL_END + + return ret; +}