fortify-headers

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

commit e892e1188129de42ea7068dbaee85e8bc62f7170
parent 62199030394acd30ab44bc21af7078ae993fd149
Author: jvoisin <julien.voisin@dustri.org>
Date:   Sat,  8 Jul 2023 21:49:15 +0200

Add tests for memcpy overflow/underflow

Diffstat:
Mtests/Makefile | 2++
Atests/test_memcpy_overwrite_over.c | 15+++++++++++++++
Atests/test_memcpy_overwrite_under.c | 15+++++++++++++++
3 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/tests/Makefile b/tests/Makefile @@ -13,6 +13,8 @@ TARGETS= \ test_memcpy_dynamic_write \ test_memcpy_static_read \ test_memcpy_dynamic_read \ + test_memcpy_overwrite_over \ + test_memcpy_overwrite_under \ test_mempcpy_static_write \ test_mempcpy_dynamic_write \ test_mempcpy_static_read \ diff --git a/tests/test_memcpy_overwrite_over.c b/tests/test_memcpy_overwrite_over.c @@ -0,0 +1,15 @@ +#include "common.h" + +#include <string.h> + +int main(int argc, char** argv) { + char buffer[9] = {'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', '\0'}; + puts(buffer); + + CHK_FAIL_START + memcpy(buffer+1, buffer, 5); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_memcpy_overwrite_under.c b/tests/test_memcpy_overwrite_under.c @@ -0,0 +1,15 @@ +#include "common.h" + +#include <string.h> + +int main(int argc, char** argv) { + char buffer[9] = {'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', '\0'}; + puts(buffer); + + CHK_FAIL_START + memcpy(buffer-1, buffer, 5); + CHK_FAIL_END + + puts(buffer); + return ret; +}