fortify-headers

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

commit 33acec595b47ec97ae57a98ec396a26f6d8e309e
parent 6939c9e0c241bb348c006d07ee423ed5aeb0e707
Author: jvoisin <julien.voisin@dustri.org>
Date:   Sun,  9 Jul 2023 16:11:24 +0200

Add tests for unistd.h

Diffstat:
Mtests/Makefile | 10++++++++++
Atests/test_confstr.c | 16++++++++++++++++
Mtests/test_getcwd.c | 4+++-
Atests/test_getdomainname.c | 18++++++++++++++++++
Atests/test_getgroups.c | 16++++++++++++++++
Atests/test_gethostname.c | 16++++++++++++++++
Atests/test_getlogin_r.c | 16++++++++++++++++
Atests/test_pread.c | 15+++++++++++++++
Atests/test_read.c | 15+++++++++++++++
Atests/test_readlink.c | 16++++++++++++++++
Atests/test_ttyname_r.c | 14++++++++++++++
Atests/test_write.c | 15+++++++++++++++
12 files changed, 170 insertions(+), 1 deletion(-)

diff --git a/tests/Makefile b/tests/Makefile @@ -38,9 +38,19 @@ TARGETS= \ test_stpncpy_overwrite_over \ test_stpncpy_overwrite_under \ test_stpncpy_static_write \ + test_confstr \ test_getcwd \ test_poll \ test_ppoll \ + test_getdomainname \ + test_getgroups \ + test_gethostname \ + test_getlogin_r \ + test_pread \ + test_read \ + test_readlink \ + test_ttyname_r \ + test_write \ .SILENT: diff --git a/tests/test_confstr.c b/tests/test_confstr.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <unistd.h> + +int main(int argc, char** argv) { + char buffer[12] = {0}; + + confstr(_CS_PATH, buffer, 10); + + CHK_FAIL_START + confstr(_CS_PATH, buffer, 14); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_getcwd.c b/tests/test_getcwd.c @@ -1,10 +1,12 @@ #include "common.h" -#include <string.h> +#include <unistd.h> int main(int argc, char** argv) { char buffer[12] = {0}; + getcwd(buffer, 10); + CHK_FAIL_START getcwd(buffer, 14); CHK_FAIL_END diff --git a/tests/test_getdomainname.c b/tests/test_getdomainname.c @@ -0,0 +1,18 @@ +#include "common.h" + +#define _GNU_SOURCE + +#include <unistd.h> + +int main(int argc, char** argv) { + char buffer[12] = {0}; + + getdomainname(buffer, 10); + + CHK_FAIL_START + getdomainname(buffer, 14); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_getgroups.c b/tests/test_getgroups.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <unistd.h> + +int main(int argc, char** argv) { + gid_t list[12] = {0}; + + getgroups(10, list); + + CHK_FAIL_START + getgroups(14, list); + CHK_FAIL_END + + puts((const char*)list); + return ret; +} diff --git a/tests/test_gethostname.c b/tests/test_gethostname.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <unistd.h> + +int main(int argc, char** argv) { + char buffer[12] = {0}; + + gethostname(buffer, 10); + + CHK_FAIL_START + gethostname(buffer, 14); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_getlogin_r.c b/tests/test_getlogin_r.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <unistd.h> + +int main(int argc, char** argv) { + char buffer[12] = {0}; + + getlogin_r(buffer, 10); + + CHK_FAIL_START + getlogin_r(buffer, 14); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_pread.c b/tests/test_pread.c @@ -0,0 +1,15 @@ +#include "common.h" + +#include <unistd.h> + +int main(int argc, char** argv) { + char buffer[12] = {0}; + + + CHK_FAIL_START + pread(0, buffer, 14, 0); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_read.c b/tests/test_read.c @@ -0,0 +1,15 @@ +#include "common.h" + +#include <unistd.h> + +int main(int argc, char** argv) { + char buffer[12] = {0}; + + + CHK_FAIL_START + read(0, buffer, 14); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_readlink.c b/tests/test_readlink.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <unistd.h> + +int main(int argc, char** argv) { + char buffer[12] = {0}; + + readlink("", buffer, 10); + + CHK_FAIL_START + readlink("", buffer, 14); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_ttyname_r.c b/tests/test_ttyname_r.c @@ -0,0 +1,14 @@ +#include "common.h" + +#include <unistd.h> + +int main(int argc, char** argv) { + char buffer[12] = {0}; + + CHK_FAIL_START + ttyname_r(0, buffer, 14); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_write.c b/tests/test_write.c @@ -0,0 +1,15 @@ +#include "common.h" + +#include <unistd.h> + +int main(int argc, char** argv) { + char buffer[12] = {0}; + + + CHK_FAIL_START + write(0, buffer, 14); + CHK_FAIL_END + + puts(buffer); + return ret; +}