fortify-headers

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

commit aceef734bdfe4f68e2227fc9ac636aae8235fa12
parent 476fbfc29fe843cf362a2e203818cbe1a97130bb
Author: jvoisin <julien.voisin@dustri.org>
Date:   Thu, 13 Apr 2023 22:46:49 +0200

Add tests for memmove

Diffstat:
Mtests/Makefile | 12++++++++----
Atests/test_memmove_dynamic_read.c | 16++++++++++++++++
Atests/test_memmove_dynamic_write.c | 16++++++++++++++++
Atests/test_memmove_static_read.c | 16++++++++++++++++
Atests/test_memmove_static_write.c | 16++++++++++++++++
5 files changed, 72 insertions(+), 4 deletions(-)

diff --git a/tests/Makefile b/tests/Makefile @@ -1,10 +1,14 @@ CC=../x86_64-linux-musl-native/bin/gcc CFLAGS=-I../include/ -D_FORTIFY_SOURCE=3 -static -O2 -TARGETS=test_memcpy_static_write \ - test_memcpy_dynamic_write \ - test_memcpy_static_read \ - test_memcpy_dynamic_read +TARGETS=test_memcpy_static_write \ + test_memcpy_dynamic_write \ + test_memcpy_static_read \ + test_memcpy_dynamic_read \ + test_memmove_static_write \ + test_memmove_dynamic_write \ + test_memmove_static_read \ + test_memmove_dynamic_read .SILENT: diff --git a/tests/test_memmove_dynamic_read.c b/tests/test_memmove_dynamic_read.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <string.h> + +int main(int argc, char** argv) { + char buffer[12] = {0}; + memmove(buffer, "1234567890", sizeof(buffer) - 1); + puts(buffer); + + CHK_FAIL_START + memmove(buffer, "123456", argc); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_memmove_dynamic_write.c b/tests/test_memmove_dynamic_write.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <string.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + memmove(buffer, "1234567890", sizeof(buffer) - 1); + puts(buffer); + + CHK_FAIL_START + memmove(buffer, "1234567890", argc); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_memmove_static_read.c b/tests/test_memmove_static_read.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <string.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + memmove(buffer, "123456", 4); + puts(buffer); + + CHK_FAIL_START + memmove(buffer, "123456", sizeof(buffer)); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_memmove_static_write.c b/tests/test_memmove_static_write.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <string.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + memmove(buffer, "1234567890", sizeof(buffer) - 1); + puts(buffer); + + CHK_FAIL_START + memmove(buffer, "1234567890", sizeof(buffer) + 1); + CHK_FAIL_END + + puts(buffer); + return ret; +}