From e441ae8c30b35ad7602ab428753afb4a335b34bf Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sun, 20 Aug 2023 18:09:14 +0200 Subject: Add hardening for strchr --- tests/Makefile | 2 ++ tests/test_strchr_dynamic_read.c | 17 +++++++++++++++++ tests/test_strchr_static_read.c | 17 +++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 tests/test_strchr_dynamic_read.c create mode 100644 tests/test_strchr_static_read.c (limited to 'tests') diff --git a/tests/Makefile b/tests/Makefile index d5f0a09..1ea610b 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -75,6 +75,8 @@ TARGETS= \ test_stpncpy_overwrite_under \ test_stpncpy_static_write \ test_strcat_static_write \ + test_strchr_dynamic_read \ + test_strchr_static_read \ test_strcpy_overwrite_over \ test_strcpy_overwrite_under \ test_strcpy_static_write \ diff --git a/tests/test_strchr_dynamic_read.c b/tests/test_strchr_dynamic_read.c new file mode 100644 index 0000000..fdd69df --- /dev/null +++ b/tests/test_strchr_dynamic_read.c @@ -0,0 +1,17 @@ +#include "common.h" + +#include + +int main(int argc, char** argv) { + char buffer[] = {'1', '2', '3', '4', '5'}; + const char* padding = "ABCDEFGHIJKLMN"; + strchr(buffer, (int)'4'); + puts(buffer); + + CHK_FAIL_START + strchr(buffer, (int)'A'); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_strchr_static_read.c b/tests/test_strchr_static_read.c new file mode 100644 index 0000000..fdd69df --- /dev/null +++ b/tests/test_strchr_static_read.c @@ -0,0 +1,17 @@ +#include "common.h" + +#include + +int main(int argc, char** argv) { + char buffer[] = {'1', '2', '3', '4', '5'}; + const char* padding = "ABCDEFGHIJKLMN"; + strchr(buffer, (int)'4'); + puts(buffer); + + CHK_FAIL_START + strchr(buffer, (int)'A'); + CHK_FAIL_END + + puts(buffer); + return ret; +} -- cgit v1.3