fortify-headers

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

commit 79447cbb8dc30e2335e3bb186de8e1172b3dff90
parent b714dbd77f79262b00298fcdb3f69bf518dcd242
Author: jvoisin <julien.voisin@dustri.org>
Date:   Thu, 22 Jun 2023 18:20:38 +0200

Add tests for mempcpy

Diffstat:
Mtests/Makefile | 4++++
Atests/test_mempcpy_dynamic_read.c | 17+++++++++++++++++
Atests/test_mempcpy_dynamic_write.c | 17+++++++++++++++++
Atests/test_mempcpy_static_read.c | 17+++++++++++++++++
Atests/test_mempcpy_static_write.c | 17+++++++++++++++++
5 files changed, 72 insertions(+), 0 deletions(-)

diff --git a/tests/Makefile b/tests/Makefile @@ -6,6 +6,10 @@ TARGETS=test_memcpy_static_write \ test_memcpy_dynamic_write \ test_memcpy_static_read \ test_memcpy_dynamic_read \ + test_mempcpy_static_write \ + test_mempcpy_dynamic_write \ + test_mempcpy_static_read \ + test_mempcpy_dynamic_read \ test_memmove_static_write \ test_memmove_dynamic_write \ test_memmove_static_read \ diff --git a/tests/test_mempcpy_dynamic_read.c b/tests/test_mempcpy_dynamic_read.c @@ -0,0 +1,17 @@ +#include "common.h" + +#define _GNU_SOURCE +#include <string.h> + +int main(int argc, char** argv) { + char buffer[12] = {0}; + mempcpy(buffer, "1234567890", sizeof(buffer) - 1); + puts(buffer); + + CHK_FAIL_START + mempcpy(buffer, "123456", argc); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_mempcpy_dynamic_write.c b/tests/test_mempcpy_dynamic_write.c @@ -0,0 +1,17 @@ +#include "common.h" + +#define _GNU_SOURCE +#include <string.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + mempcpy(buffer, "1234567890", sizeof(buffer) - 1); + puts(buffer); + + CHK_FAIL_START + mempcpy(buffer, "1234567890", argc); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_mempcpy_static_read.c b/tests/test_mempcpy_static_read.c @@ -0,0 +1,17 @@ +#include "common.h" + +#define _GNU_SOURCE +#include <string.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + mempcpy(buffer, "123456", 4); + puts(buffer); + + CHK_FAIL_START + mempcpy(buffer, "123456", sizeof(buffer)); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_mempcpy_static_write.c b/tests/test_mempcpy_static_write.c @@ -0,0 +1,17 @@ +#include "common.h" + +#define _GNU_SOURCE +#include <string.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + mempcpy(buffer, "1234567890", sizeof(buffer) - 1); + puts(buffer); + + CHK_FAIL_START + mempcpy(buffer, "1234567890", sizeof(buffer) + 1); + CHK_FAIL_END + + puts(buffer); + return ret; +}