fortify-headers

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

commit 8b6129312db7b2405f883c4080b835c69a855627
parent 759cb4697e9bba06a5aabad9899d0700f57051da
Author: jvoisin <julien.voisin@dustri.org>
Date:   Tue, 11 Jul 2023 00:14:13 +0200

Add more dynamic tests

Diffstat:
Mtests/Makefile | 18++++++++++++------
Atests/test_fgets_dynamic.c | 15+++++++++++++++
Rtests/test_fgets.c -> tests/test_fgets_static.c | 0
Atests/test_fread_overwrite_dynamic.c | 18++++++++++++++++++
Rtests/test_fread_overwrite.c -> tests/test_fread_overwrite_static.c | 0
Atests/test_fwrite_overwrite_dynamic.c | 18++++++++++++++++++
Rtests/test_fwrite_overwrite.c -> tests/test_fwrite_overwrite_static.c | 0
Atests/test_poll_dynamic.c | 14++++++++++++++
Rtests/test_poll.c -> tests/test_poll_static.c | 0
Atests/test_ppoll_dynamic.c | 15+++++++++++++++
Rtests/test_ppoll.c -> tests/test_ppoll_static.c | 0
Atests/test_vsnprintf_dynamic.c | 28++++++++++++++++++++++++++++
Rtests/test_vsnprintf.c -> tests/test_vsnprintf_static.c | 0
13 files changed, 120 insertions(+), 6 deletions(-)

diff --git a/tests/Makefile b/tests/Makefile @@ -13,11 +13,14 @@ TARGETS= \ test_bzero_static_write \ test_confstr_dynamic \ test_confstr_static \ - test_fgets \ + test_fgets_dynamic \ + test_fgets_static \ test_fread_int_overflow \ - test_fread_overwrite \ + test_fread_overwrite_dynamic \ + test_fread_overwrite_static \ test_fwrite_int_overflow \ - test_fwrite_overwrite \ + test_fwrite_overwrite_dynamic \ + test_fwrite_overwrite_static \ test_getcwd_dynamic \ test_getcwd_static \ test_getdomainname_dynamic \ @@ -45,8 +48,10 @@ TARGETS= \ test_mempcpy_static_write \ test_memset_dynamic_write \ test_memset_static_write \ - test_poll \ - test_ppoll \ + test_poll_dynamic \ + test_poll_static \ + test_ppoll_dynamic \ + test_ppoll_static \ test_pread_dynamic \ test_pread_static \ test_read_dynamic \ @@ -77,7 +82,8 @@ TARGETS= \ test_strncpy_static_write \ test_ttyname_r_dynamic \ test_ttyname_r_static \ - test_vsnprintf \ + test_vsnprintf_dynamic \ + test_vsnprintf_static \ test_vsprintf \ test_write_dynamic \ test_write_static \ diff --git a/tests/test_fgets_dynamic.c b/tests/test_fgets_dynamic.c @@ -0,0 +1,15 @@ +#include "common.h" + +#define _GNU_SOURCE +#include <poll.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + + CHK_FAIL_START + fgets(buffer, argc, NULL); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_fgets.c b/tests/test_fgets_static.c diff --git a/tests/test_fread_overwrite_dynamic.c b/tests/test_fread_overwrite_dynamic.c @@ -0,0 +1,18 @@ +#include <assert.h> + +#include "common.h" + +#include <stdio.h> + +int main(int argc, char** argv) { + char buffer[12] = {0}; + + assert(sizeof(buffer - 2) * argc > sizeof(buffer)); + + CHK_FAIL_START + fread(buffer, sizeof(buffer) - 2, argc, NULL); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_fread_overwrite.c b/tests/test_fread_overwrite_static.c diff --git a/tests/test_fwrite_overwrite_dynamic.c b/tests/test_fwrite_overwrite_dynamic.c @@ -0,0 +1,18 @@ +#include <assert.h> + +#include "common.h" + +#include <stdio.h> + +int main(int argc, char** argv) { + char buffer[12] = {0}; + + assert(sizeof(buffer - 2) * argc > sizeof(buffer)); + + CHK_FAIL_START + fwrite(buffer, sizeof(buffer) - 2, argc, NULL); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_fwrite_overwrite.c b/tests/test_fwrite_overwrite_static.c diff --git a/tests/test_poll_dynamic.c b/tests/test_poll_dynamic.c @@ -0,0 +1,14 @@ +#include "common.h" + +#include <poll.h> + +int main(int argc, char** argv) { + struct pollfd buffer[8] = {0}; + + CHK_FAIL_START + poll(buffer, argc, 0); + CHK_FAIL_END + + puts((const char*)buffer); + return ret; +} diff --git a/tests/test_poll.c b/tests/test_poll_static.c diff --git a/tests/test_ppoll_dynamic.c b/tests/test_ppoll_dynamic.c @@ -0,0 +1,15 @@ +#include "common.h" + +#define _GNU_SOURCE +#include <poll.h> + +int main(int argc, char** argv) { + struct pollfd buffer[8] = {0}; + + CHK_FAIL_START + ppoll(buffer, argc, NULL, NULL); + CHK_FAIL_END + + puts((const char*)buffer); + return ret; +} diff --git a/tests/test_ppoll.c b/tests/test_ppoll_static.c diff --git a/tests/test_vsnprintf_dynamic.c b/tests/test_vsnprintf_dynamic.c @@ -0,0 +1,28 @@ +#include "common.h" + +#include <stdarg.h> +#include <unistd.h> + +char buffer[8] = {0}; + +int msg_valid(int n, const char * format, ... ) { + va_list args; + va_start (args, format); + vsnprintf(buffer, n, format, args); + va_end (args); +} + +int msg(int n, const char * format, ... ) { + va_list args; + va_start (args, format); + CHK_FAIL_START + vsnprintf(buffer, n, format, args); + CHK_FAIL_END + va_end (args); + return ret; +} + +int main(int argc, char** argv) { + msg_valid(sizeof(buffer), "%s", "1234567890ABCDEF"); + return msg(argc, "%s", "1234567890ABCDEF"); +} diff --git a/tests/test_vsnprintf.c b/tests/test_vsnprintf_static.c