commit 589570112910c52b8cb21a83bce6a3548cfea15e parent 9638684324f7fa849a2ba07c48d579a4fdeb7fac Author: jvoisin <julien.voisin@dustri.org> Date: Fri, 31 Oct 2025 15:18:10 +0100 Add a testsuite Co-Authored-By: q66 <q66@chimera-linux.org> Diffstat:
110 files changed, 1995 insertions(+), 0 deletions(-)
diff --git a/tests/Makefile b/tests/Makefile @@ -0,0 +1,147 @@ +MACHINE := $(shell uname -m) +CFLAGS ?= -std=gnu99 +CFLAGS += -I../include/ -D_FORTIFY_SOURCE=3 -static -O2 -Wall -Wextra -Werror -Werror=pointer-arith +CFLAGS += -Wno-format -Wno-array-bounds -Wno-shift-count-negative -Wno-unused-variable -Wno-unused-parameter + +RUNTIME_TARGETS= \ + test_FD_CLR_SETSIZE \ + test_FD_CLR_negative \ + test_FD_SET_SETSIZE \ + test_FD_SET_negative \ + test_bcopy_dynamic_read \ + test_bcopy_dynamic_write \ + test_bcopy_static_read \ + test_bcopy_static_write \ + test_bzero_dynamic_write \ + test_bzero_static_write \ + test_compile \ + test_confstr_dynamic \ + test_fgets_dynamic \ + test_fgets_static \ + test_fgetws_dynamic \ + test_fgetws_static \ + test_fread_int_overflow \ + test_fread_overwrite_dynamic \ + test_fread_overwrite_static \ + test_fwrite_int_overflow \ + test_fwrite_overwrite_dynamic \ + test_fwrite_overwrite_static \ + test_getcwd_dynamic \ + test_getcwd_static \ + test_getdomainname_dynamic \ + test_getdomainname_static \ + test_getgroups_dynamic \ + test_getgroups_static \ + test_gethostname_dynamic \ + test_gethostname_static \ + test_getlogin_r_dynamic \ + test_getlogin_r_static \ + test_memcpy_dynamic_read \ + test_memcpy_dynamic_write \ + test_memcpy_null_dst \ + test_memcpy_null_src \ + test_memcpy_static_read \ + test_memmove_dynamic_read \ + test_memmove_dynamic_write \ + test_memmove_null_dst \ + test_memmove_null_src \ + test_memmove_static_read \ + test_memmove_static_write \ + test_mempcpy_dynamic_read \ + test_mempcpy_dynamic_write \ + test_mempcpy_static_read \ + test_mempcpy_static_write \ + test_memset_dynamic_write \ + test_memset_null \ + test_memset_static_write \ + test_poll_dynamic \ + test_poll_static \ + test_ppoll_dynamic \ + test_ppoll_static \ + test_read_dynamic \ + test_read_static \ + test_readlink_dynamic \ + test_readlink_static \ + test_recv_dynamic \ + test_recv_static \ + test_recvfrom_dynamic \ + test_recvfrom_static \ + test_send_dynamic \ + test_send_static \ + test_sendto_dynamic \ + test_sendto_static \ + test_sprintf \ + test_sprintf_62 \ + test_stpcpy_dynamic_write \ + test_stpcpy_static_write \ + test_stpncpy_dynamic_write \ + test_stpncpy_static_write \ + test_strcat_static_write \ + test_strcpy_dynamic_write \ + test_strcpy_static_write \ + test_strlcat_dynamic_write \ + test_strlcat_static_write \ + test_strlcpy_dynamic_write \ + test_strlcpy_static_write \ + test_strncat_dynamic_write \ + test_strncat_static_write \ + test_strncpy_dynamic_write \ + test_strncpy_static_write \ + test_swab_dynamic_read \ + test_swab_dynamic_write \ + test_swab_static_read \ + test_ttyname_r_dynamic \ + test_ttyname_r_static \ + test_vsnprintf_dynamic \ + test_vsnprintf_static \ + test_vsprintf \ + test_wcscat_static_write \ + test_wcscpy_static_write \ + test_wcsncat_static_write \ + test_wcsncpy_static_write \ + test_wmemcpy_dynamic_write \ + test_wmemcpy_static_write \ + test_wmemmove_dynamic_write \ + test_wmemmove_static_write \ + test_wmemset_dynamic \ + test_wmemset_static \ + test_write_dynamic \ + test_write_static \ + +gcc: CC=../$(MACHINE)-linux-musl-native/bin/gcc +gcc: CFLAGS += -Wno-stringop-overread -Wno-stringop-overflow -ffreestanding +gcc: $(RUNTIME_TARGETS) + +clang: CC=clang +clang: CFLAGS+=-I/usr/include/$(MACHINE)-linux-musl +clang: CFLAGS+=-I../$(MACHINE)-linux-musl-native/include/ +clang: CFLAGS+=-I$(MACHINE)-linux-musl-native/include/ +clang: CFLAGS+=-nostdinc +clang: CXX=clang++ +clang: CXXFLAGS+=-I/usr/include/$(MACHINE)-linux-musl +clang: CXXFLAGS+=-I../$(MACHINE)-linux-musl-native/include/ +clang: CXXFLAGS+=-I$(MACHINE)-linux-musl-native/include/ +clang: CXXFLAGS+=-nostdinc +clang: $(RUNTIME_TARGETS) cpp + +all: gcc + + +$(RUNTIME_TARGETS): %: %.c + $(CC) $(CFLAGS) -o $@ $< + +cpp: test_compile.cc + $(CXX) $(CXXFLAGS) test_compile.cc -o ./test_compile_cc + timeout 1s ./test_compile_cc 1234567890 2 3 4 5 6 7 8 9 0 >/dev/null && echo "$(EXE) OK" || echo "$(EXE) FAIL"; \ + +run: $(RUNTIME_TARGETS) + $(foreach EXE, $(RUNTIME_TARGETS), \ + timeout 1s ./$(EXE) 1234567890 2 3 4 5 6 7 8 9 0 >/dev/null && echo "$(EXE) OK" || echo "$(EXE) FAIL"; \ + ) + +clean: + $(foreach EXE, $(RUNTIME_TARGETS), \ + rm -f ./$(EXE) \ + ) + rm -f ./test_compile_cc + diff --git a/tests/common.h b/tests/common.h @@ -0,0 +1,66 @@ +/* Copyright (C) 2004-2020 Free Software Foundation, Inc. + This snippet is taken from debug/tst-chk1 in the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <https://www.gnu.org/licenses/>. */ + +#define _POSIX_C_SOURCE 2 +#define _XOPEN_SOURCE 700 + +#include <setjmp.h> +#include <unistd.h> +#include <signal.h> +#include <stdio.h> + +volatile int chk_fail_ok; +volatile int ret; +jmp_buf chk_fail_buf; + +static void +handler (int sig) +{ + if (chk_fail_ok) + { + chk_fail_ok = 0; + longjmp (chk_fail_buf, 1); + } + else + _exit (127); +} + +void +__attribute__((constructor)) +set_fortify_handler (void) +{ + struct sigaction sa; + + sa.sa_handler = handler; + sa.sa_flags = 0; + sigemptyset (&sa.sa_mask); + + sigaction (SIGILL, &sa, NULL); + sigaction (SIGTRAP, &sa, NULL); +} + +#define FAIL() \ + do { fprintf (stderr, "Failure in %s:%d\n", __FILE__, __LINE__); ret = 1; } while (0) +#define CHK_FAIL_START \ + chk_fail_ok = 1; \ + if (! setjmp (chk_fail_buf)) \ + { +#define CHK_FAIL_END \ + chk_fail_ok = 0; \ + FAIL (); \ + } + diff --git a/tests/test_FD_CLR_SETSIZE.c b/tests/test_FD_CLR_SETSIZE.c @@ -0,0 +1,14 @@ +#include "common.h" + +#include <sys/select.h> + +int main(int argc, char** argv) { + fd_set rfds; + + CHK_FAIL_START + FD_CLR(FD_SETSIZE, &rfds); + CHK_FAIL_END + + puts((const char*)&rfds); + return ret; +} diff --git a/tests/test_FD_CLR_negative.c b/tests/test_FD_CLR_negative.c @@ -0,0 +1,14 @@ +#include "common.h" + +#include <sys/select.h> + +int main(int argc, char** argv) { + fd_set rfds; + + CHK_FAIL_START + FD_CLR(-1, &rfds); + CHK_FAIL_END + + puts((const char*)&rfds); + return ret; +} diff --git a/tests/test_FD_SET_SETSIZE.c b/tests/test_FD_SET_SETSIZE.c @@ -0,0 +1,14 @@ +#include "common.h" + +#include <sys/select.h> + +int main(int argc, char** argv) { + fd_set rfds; + + CHK_FAIL_START + FD_SET(FD_SETSIZE, &rfds); + CHK_FAIL_END + + puts((const char*)&rfds); + return ret; +} diff --git a/tests/test_FD_SET_negative.c b/tests/test_FD_SET_negative.c @@ -0,0 +1,14 @@ +#include "common.h" + +#include <sys/select.h> + +int main(int argc, char** argv) { + fd_set rfds; + + CHK_FAIL_START + FD_SET(-1, &rfds); + CHK_FAIL_END + + puts((const char*)&rfds); + return ret; +} diff --git a/tests/test_bcopy_dynamic_read.c b/tests/test_bcopy_dynamic_read.c @@ -0,0 +1,18 @@ +#define _GNU_SOURCE + +#include "common.h" + +#include <strings.h> + +int main(int argc, char** argv) { + char buffer[12] = {0}; + bcopy("1234567890", buffer, sizeof(buffer) - 1); + puts(buffer); + + CHK_FAIL_START + bcopy("123456", buffer, argc); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_bcopy_dynamic_write.c b/tests/test_bcopy_dynamic_write.c @@ -0,0 +1,18 @@ +#define _GNU_SOURCE + +#include "common.h" + +#include <string.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + bcopy("1234567890", buffer, sizeof(buffer) - 1); + puts(buffer); + + CHK_FAIL_START + bcopy("1234567890", buffer, argc); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_bcopy_static_read.c b/tests/test_bcopy_static_read.c @@ -0,0 +1,18 @@ +#define _GNU_SOURCE + +#include "common.h" + +#include <string.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + bcopy("123456", buffer, 4); + puts(buffer); + + CHK_FAIL_START + bcopy("123456", buffer, sizeof(buffer)); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_bcopy_static_write.c b/tests/test_bcopy_static_write.c @@ -0,0 +1,18 @@ +#define _GNU_SOURCE + +#include "common.h" + +#include <string.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + bcopy("1234567890", buffer, sizeof(buffer) - 1); + puts(buffer); + + CHK_FAIL_START + bcopy("1234567890", buffer, sizeof(buffer) + 1); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_bzero_dynamic_write.c b/tests/test_bzero_dynamic_write.c @@ -0,0 +1,18 @@ +#define _GNU_SOURCE + +#include "common.h" + +#include <strings.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + bzero(buffer, sizeof(buffer) - 1); + puts(buffer); + + CHK_FAIL_START + bzero(buffer, argc); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_bzero_static_write.c b/tests/test_bzero_static_write.c @@ -0,0 +1,18 @@ +#define _GNU_SOURCE + +#include "common.h" + +#include <strings.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + bzero(buffer, sizeof(buffer) - 1); + puts(buffer); + + CHK_FAIL_START + bzero(buffer, sizeof(buffer) + 1); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_compile.c b/tests/test_compile.c @@ -0,0 +1,18 @@ +#include "common.h" + +#include <poll.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> +#include <unistd.h> +#include <wchar.h> + +#include <sys/select.h> +#include <sys/socket.h> +#include <sys/stat.h> + +/* Check that all headers are compiling.*/ +int main(int argc, char** argv) { + return 0; +} diff --git a/tests/test_compile.cc b/tests/test_compile.cc @@ -0,0 +1,18 @@ +#include "common.h" + +#include <poll.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> +#include <unistd.h> +#include <wchar.h> + +#include <sys/select.h> +#include <sys/socket.h> +#include <sys/stat.h> + +// Check that all headers are compiling. +int main(int argc, char** argv) { + return 0; +} diff --git a/tests/test_confstr_dynamic.c b/tests/test_confstr_dynamic.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <unistd.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + + confstr(_CS_PATH, buffer, 6); + + CHK_FAIL_START + confstr(_CS_PATH, buffer, argc); + CHK_FAIL_END + + puts(buffer); + return ret; +} 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 + (void)fgets(buffer, argc, NULL); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_fgets_static.c b/tests/test_fgets_static.c @@ -0,0 +1,15 @@ +#include "common.h" + +#define _GNU_SOURCE +#include <poll.h> + +int main(int argc, char** argv) { + char buffer[12] = {0}; + + CHK_FAIL_START + (void)fgets(buffer, 14, NULL); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_fgetws_dynamic.c b/tests/test_fgetws_dynamic.c @@ -0,0 +1,15 @@ +#include "common.h" + +#define _GNU_SOURCE +#include <wchar.h> + +int main(int argc, char** argv) { + wchar_t buffer[8] = {L'A'}; + + CHK_FAIL_START + fgetws(buffer, argc, NULL); + CHK_FAIL_END + + printf("%ls\n", buffer); + return ret; +} diff --git a/tests/test_fgetws_static.c b/tests/test_fgetws_static.c @@ -0,0 +1,15 @@ +#include "common.h" + +#define _GNU_SOURCE +#include <wchar.h> + +int main(int argc, char** argv) { + wchar_t buffer[12] = {L'A'}; + + CHK_FAIL_START + fgetws(buffer, 14, NULL); + CHK_FAIL_END + + printf("%ls\n", buffer); + return ret; +} diff --git a/tests/test_fread_int_overflow.c b/tests/test_fread_int_overflow.c @@ -0,0 +1,14 @@ +#include "common.h" + +#include <stdio.h> + +int main(int argc, char** argv) { + char buffer[12] = {0}; + + CHK_FAIL_START + fread(buffer, (size_t)-1, (size_t)-1, stdin); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_fread_overwrite_dynamic.c b/tests/test_fread_overwrite_dynamic.c @@ -0,0 +1,17 @@ +#include "common.h" + +#include <assert.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_static.c b/tests/test_fread_overwrite_static.c @@ -0,0 +1,17 @@ +#include "common.h" + +#include <assert.h> +#include <stdio.h> + +int main(int argc, char** argv) { + char buffer[12] = {0}; + + assert((sizeof(buffer) - 2) * 10 > sizeof(buffer)); + + CHK_FAIL_START + fread(buffer, sizeof(buffer) - 2, 10, stdin); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_fwrite_int_overflow.c b/tests/test_fwrite_int_overflow.c @@ -0,0 +1,14 @@ +#include "common.h" + +#include <stdio.h> + +int main(int argc, char** argv) { + char buffer[12] = {0}; + + CHK_FAIL_START + fwrite(buffer, (size_t)-1, (size_t)-1, stdin); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_fwrite_overwrite_dynamic.c b/tests/test_fwrite_overwrite_dynamic.c @@ -0,0 +1,17 @@ +#include "common.h" + +#include <assert.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, stdin); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_fwrite_overwrite_static.c b/tests/test_fwrite_overwrite_static.c @@ -0,0 +1,17 @@ +#include "common.h" + +#include <assert.h> +#include <stdio.h> + +int main(int argc, char** argv) { + char buffer[12] = {0}; + + assert((sizeof(buffer) - 2) * 10 > sizeof(buffer)); + + CHK_FAIL_START + fwrite(buffer, sizeof(buffer) - 2, 10, stdin); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_getcwd_dynamic.c b/tests/test_getcwd_dynamic.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <unistd.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + + getcwd(buffer, 6); + + CHK_FAIL_START + getcwd(buffer, argc); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_getcwd_static.c b/tests/test_getcwd_static.c @@ -0,0 +1,16 @@ +#include "common.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 + + puts(buffer); + return ret; +} diff --git a/tests/test_getdomainname_dynamic.c b/tests/test_getdomainname_dynamic.c @@ -0,0 +1,19 @@ +#define _GNU_SOURCE +#define _DEFAULT_SOURCE + +#include "common.h" + +#include <unistd.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + + getdomainname(buffer, 6); + + CHK_FAIL_START + getdomainname(buffer, argc); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_getdomainname_static.c b/tests/test_getdomainname_static.c @@ -0,0 +1,19 @@ +#define _GNU_SOURCE +#define _DEFAULT_SOURCE + +#include "common.h" + +#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_dynamic.c b/tests/test_getgroups_dynamic.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <unistd.h> + +int main(int argc, char** argv) { + gid_t list[8] = {0}; + + getgroups(6, list); + + CHK_FAIL_START + getgroups(argc, list); + CHK_FAIL_END + + puts((const char*)list); + return ret; +} diff --git a/tests/test_getgroups_static.c b/tests/test_getgroups_static.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_dynamic.c b/tests/test_gethostname_dynamic.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <unistd.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + + gethostname(buffer, 6); + + CHK_FAIL_START + gethostname(buffer, argc); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_gethostname_static.c b/tests/test_gethostname_static.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_dynamic.c b/tests/test_getlogin_r_dynamic.c @@ -0,0 +1,19 @@ +#include "common.h" + +#include <unistd.h> + +int main(int argc, char** argv) { +#if _REENTRANT || _POSIX_C_SOURCE >= 199506L + char buffer[8] = {0}; + + getlogin_r(buffer, 6); + + CHK_FAIL_START + getlogin_r(buffer, argc); + CHK_FAIL_END + + puts(buffer); + return ret; +#endif + return 0; +} diff --git a/tests/test_getlogin_r_static.c b/tests/test_getlogin_r_static.c @@ -0,0 +1,19 @@ +#include "common.h" + +#include <unistd.h> + +int main(int argc, char** argv) { +#if _REENTRANT || _POSIX_C_SOURCE >= 199506L + char buffer[12] = {0}; + + getlogin_r(buffer, 10); + + CHK_FAIL_START + getlogin_r(buffer, 14); + CHK_FAIL_END + + puts(buffer); + return ret; +#endif + return 0; +} diff --git a/tests/test_memcpy_dynamic_read.c b/tests/test_memcpy_dynamic_read.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <string.h> + +int main(int argc, char** argv) { + char buffer[12] = {0}; + memcpy(buffer, "1234567890", sizeof(buffer) - 1); + puts(buffer); + + CHK_FAIL_START + memcpy(buffer, "123456", argc); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_memcpy_dynamic_write.c b/tests/test_memcpy_dynamic_write.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <string.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + memcpy(buffer, "1234567890", sizeof(buffer) - 1); + puts(buffer); + + CHK_FAIL_START + memcpy(buffer, "1234567890", argc); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_memcpy_null_dst.c b/tests/test_memcpy_null_dst.c @@ -0,0 +1,14 @@ +#include "common.h" + +#include <string.h> + +int main(int argc, char** argv) { + char buffer[12] = {0}; + + CHK_FAIL_START + memcpy(buffer, NULL, 0); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_memcpy_null_src.c b/tests/test_memcpy_null_src.c @@ -0,0 +1,14 @@ +#include "common.h" + +#include <string.h> + +int main(int argc, char** argv) { + char buffer[12] = {0}; + + CHK_FAIL_START + memcpy(NULL, buffer, 0); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_memcpy_static_read.c b/tests/test_memcpy_static_read.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <string.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + memcpy(buffer, "123456", 4); + puts(buffer); + + CHK_FAIL_START + memcpy(buffer, "123456", sizeof(buffer)); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_memcpy_static_write.c b/tests/test_memcpy_static_write.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <string.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + memcpy(buffer, "1234567890", sizeof(buffer) - 1); + puts(buffer); + + CHK_FAIL_START + memcpy(buffer, "1234567890", sizeof(buffer) + 1); + CHK_FAIL_END + + puts(buffer); + return ret; +} 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_null_dst.c b/tests/test_memmove_null_dst.c @@ -0,0 +1,14 @@ +#include "common.h" + +#include <string.h> + +int main(int argc, char** argv) { + char buffer[12] = {0}; + + CHK_FAIL_START + memmove(buffer, NULL, 0); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_memmove_null_src.c b/tests/test_memmove_null_src.c @@ -0,0 +1,14 @@ +#include "common.h" + +#include <string.h> + +int main(int argc, char** argv) { + char buffer[12] = {0}; + + CHK_FAIL_START + memmove(NULL, buffer, 0); + 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}; + (void)memmove(buffer, "1234567890", sizeof(buffer) - 1); + puts(buffer); + + CHK_FAIL_START + (void)memmove(buffer, "1234567890", sizeof(buffer) + 1); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_mempcpy_dynamic_read.c b/tests/test_mempcpy_dynamic_read.c @@ -0,0 +1,19 @@ +#include "common.h" + +#define _GNU_SOURCE +#include <string.h> + +int main(int argc, char** argv) { +#if !defined(__clang__) + char buffer[12] = {0}; + mempcpy(buffer, "1234567890", sizeof(buffer) - 1); + puts(buffer); + + CHK_FAIL_START + mempcpy(buffer, "123456", argc); + CHK_FAIL_END + + puts(buffer); +#endif + return ret; +} diff --git a/tests/test_mempcpy_dynamic_write.c b/tests/test_mempcpy_dynamic_write.c @@ -0,0 +1,19 @@ +#include "common.h" + +#define _GNU_SOURCE +#include <string.h> + +int main(int argc, char** argv) { +#if !defined(__clang__) + char buffer[8] = {0}; + mempcpy(buffer, "1234567890", sizeof(buffer) - 1); + puts(buffer); + + CHK_FAIL_START + mempcpy(buffer, "1234567890", argc); + CHK_FAIL_END + + puts(buffer); +#endif + return ret; +} diff --git a/tests/test_mempcpy_static_read.c b/tests/test_mempcpy_static_read.c @@ -0,0 +1,19 @@ +#include "common.h" + +#define _GNU_SOURCE +#include <string.h> + +int main(int argc, char** argv) { +#if !defined(__clang__) + char buffer[8] = {0}; + mempcpy(buffer, "123456", 4); + puts(buffer); + + CHK_FAIL_START + mempcpy(buffer, "123456", sizeof(buffer)); + CHK_FAIL_END + + puts(buffer); +#endif + return ret; +} diff --git a/tests/test_mempcpy_static_write.c b/tests/test_mempcpy_static_write.c @@ -0,0 +1,19 @@ +#include "common.h" + +#define _GNU_SOURCE +#include <string.h> + +int main(int argc, char** argv) { +#if !defined(__clang__) + 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); +#endif + return ret; +} diff --git a/tests/test_memset_dynamic_write.c b/tests/test_memset_dynamic_write.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <string.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + memset(buffer, 0, sizeof(buffer) - 1); + puts(buffer); + + CHK_FAIL_START + memset(buffer, 0, argc); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_memset_null.c b/tests/test_memset_null.c @@ -0,0 +1,11 @@ +#include "common.h" + +#include <string.h> + +int main(int argc, char** argv) { + CHK_FAIL_START + memset(NULL, 0, 0); + CHK_FAIL_END + + return ret; +} diff --git a/tests/test_memset_static_write.c b/tests/test_memset_static_write.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <string.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + memset(buffer, 0, sizeof(buffer) - 1); + puts(buffer); + + CHK_FAIL_START + memset(buffer, 0, sizeof(buffer) + 1); + CHK_FAIL_END + + puts(buffer); + return ret; +} 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_static.c b/tests/test_poll_static.c @@ -0,0 +1,14 @@ +#include "common.h" + +#include <poll.h> + +int main(int argc, char** argv) { + struct pollfd buffer[12] = {0}; + + CHK_FAIL_START + poll(buffer, 14, 0); + CHK_FAIL_END + + puts((const char*)buffer); + return ret; +} diff --git a/tests/test_ppoll_dynamic.c b/tests/test_ppoll_dynamic.c @@ -0,0 +1,17 @@ +#include "common.h" + +#define _GNU_SOURCE +#include <poll.h> + +int main(int argc, char** argv) { +#if !defined(__clang__) + struct pollfd buffer[8] = {0}; + + CHK_FAIL_START + ppoll(buffer, argc, NULL, NULL); + CHK_FAIL_END + + puts((const char*)buffer); +#endif + return ret; +} diff --git a/tests/test_ppoll_static.c b/tests/test_ppoll_static.c @@ -0,0 +1,17 @@ +#include "common.h" + +#define _GNU_SOURCE +#include <poll.h> + +int main(int argc, char** argv) { +#if !defined(__clang__) + struct pollfd buffer[12] = {0}; + + CHK_FAIL_START + ppoll(buffer, 14, NULL, NULL); + CHK_FAIL_END + + puts((const char*)buffer); +#endif + return ret; +} diff --git a/tests/test_read_dynamic.c b/tests/test_read_dynamic.c @@ -0,0 +1,14 @@ +#include "common.h" + +#include <unistd.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + + CHK_FAIL_START + read(0, buffer, argc); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_read_static.c b/tests/test_read_static.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_dynamic.c b/tests/test_readlink_dynamic.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <unistd.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + + readlink("", buffer, 6); + + CHK_FAIL_START + readlink("", buffer, argc); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_readlink_static.c b/tests/test_readlink_static.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_recv_dynamic.c b/tests/test_recv_dynamic.c @@ -0,0 +1,14 @@ +#include "common.h" + +#include <sys/socket.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + + CHK_FAIL_START + recv(0, buffer, argc, 0); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_recv_static.c b/tests/test_recv_static.c @@ -0,0 +1,14 @@ +#include "common.h" + +#include <sys/socket.h> + +int main(int argc, char** argv) { + char buffer[12] = {0}; + + CHK_FAIL_START + recv(0, buffer, 14, 0); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_recvfrom_dynamic.c b/tests/test_recvfrom_dynamic.c @@ -0,0 +1,14 @@ +#include "common.h" + +#include <sys/socket.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + + CHK_FAIL_START + recvfrom(0, buffer, argc, 0, NULL, NULL); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_recvfrom_static.c b/tests/test_recvfrom_static.c @@ -0,0 +1,14 @@ +#include "common.h" + +#include <sys/socket.h> + +int main(int argc, char** argv) { + char buffer[12] = {0}; + + CHK_FAIL_START + recvfrom(0, buffer, 14, 0, NULL, NULL); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_select_dynamic.c b/tests/test_select_dynamic.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <sys/select.h> + +int main(int argc, char** argv) { +#if !defined(__clang__) + fd_set rfds; + + CHK_FAIL_START + select(FD_SETSIZE + argc, &rfds, NULL, NULL, NULL); + CHK_FAIL_END + + puts((const char*)&rfds); +#endif + return ret; +} diff --git a/tests/test_select_static.c b/tests/test_select_static.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <sys/select.h> + +int main(int argc, char** argv) { +#if !defined(__clang__) + fd_set rfds; + + CHK_FAIL_START + select(1337, &rfds, NULL, NULL, NULL); + CHK_FAIL_END + + puts((const char*)&rfds); +#endif + return ret; +} diff --git a/tests/test_send_dynamic.c b/tests/test_send_dynamic.c @@ -0,0 +1,14 @@ +#include "common.h" + +#include <sys/socket.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + + CHK_FAIL_START + send(0, buffer, argc, 0); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_send_static.c b/tests/test_send_static.c @@ -0,0 +1,14 @@ +#include "common.h" + +#include <sys/socket.h> + +int main(int argc, char** argv) { + char buffer[12] = {0}; + + CHK_FAIL_START + send(0, buffer, 14, 0); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_sendto_dynamic.c b/tests/test_sendto_dynamic.c @@ -0,0 +1,14 @@ +#include "common.h" + +#include <sys/socket.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + + CHK_FAIL_START + sendto(0, buffer, argc, 0, NULL, 0); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_sendto_static.c b/tests/test_sendto_static.c @@ -0,0 +1,14 @@ +#include "common.h" + +#include <sys/socket.h> + +int main(int argc, char** argv) { + char buffer[12] = {0}; + + CHK_FAIL_START + sendto(0, buffer, 14, 0, NULL, 0); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_sprintf.c b/tests/test_sprintf.c @@ -0,0 +1,9 @@ +#include "common.h" + +#include <stdio.h> + +int main(int argc, char** argv) { + char buffer[12] = {0}; + sprintf(buffer, "%s", "1234567"); + return 0; +} diff --git a/tests/test_sprintf_62.c b/tests/test_sprintf_62.c @@ -0,0 +1,21 @@ +#include "common.h" + +#include <stdio.h> + +static char *offstr(char *str) +{ + int len = 0; + + len = sprintf(str, "%s+0x%lx", "foo", (long unsigned int)0); + sprintf(str+len, " (%s+0x%lx)","bar", (long unsigned int)0); + if (len < 0) + return NULL; + return str; +} + +int main() { + char buf[100]; + char *c = offstr(buf); + printf("%s\n", c); + return 0; +} diff --git a/tests/test_stpcpy_dynamic_write.c b/tests/test_stpcpy_dynamic_write.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <string.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + stpcpy(buffer, "1234567"); + puts(buffer); + + CHK_FAIL_START + stpcpy(buffer, argv[1]); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_stpcpy_static_write.c b/tests/test_stpcpy_static_write.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <string.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + stpcpy(buffer, "1234567"); + puts(buffer); + + CHK_FAIL_START + stpcpy(buffer, "1234567890"); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_stpncpy_dynamic_write.c b/tests/test_stpncpy_dynamic_write.c @@ -0,0 +1,17 @@ +#include "common.h" + +#include <string.h> + +int main(int argc, char** argv) { + char buffer[] = {'A', 'B', 'C', 'D', 'E', 'F'}; + + stpncpy(buffer, "1234567", 3); + puts(buffer); + + CHK_FAIL_START + stpncpy(buffer, argv[1], argc); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_stpncpy_static_write.c b/tests/test_stpncpy_static_write.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <string.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + stpncpy(buffer, "1234567", 5); + puts(buffer); + + CHK_FAIL_START + stpncpy(buffer, "1234567890", 10); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_strcat_static_write.c b/tests/test_strcat_static_write.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <string.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + strcat(buffer, "1234567"); + puts(buffer); + + CHK_FAIL_START + strcat(buffer, "1234567890"); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_strcpy_dynamic_write.c b/tests/test_strcpy_dynamic_write.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <string.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + strcpy(buffer, "1234567"); + puts(buffer); + + CHK_FAIL_START + strcpy(buffer, argv[1]); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_strcpy_static_write.c b/tests/test_strcpy_static_write.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <string.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + strcpy(buffer, "1234567"); + puts(buffer); + + CHK_FAIL_START + strcpy(buffer, "1234567890"); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_strlcat_dynamic_write.c b/tests/test_strlcat_dynamic_write.c @@ -0,0 +1,21 @@ +#define _GNU_SOURCE +#define _BSD_SOURCE + +#include "common.h" + +#include <string.h> + +int main(int argc, char** argv) { +#if !defined(__clang__) + char buffer[8] = {0}; + strlcat(buffer, "1234567", sizeof(buffer)); + puts(buffer); + + CHK_FAIL_START + strlcat(buffer, argv[1], argc); + CHK_FAIL_END + + puts(buffer); +#endif + return ret; +} diff --git a/tests/test_strlcat_static_write.c b/tests/test_strlcat_static_write.c @@ -0,0 +1,21 @@ +#define _GNU_SOURCE +#define _BSD_SOURCE + +#include "common.h" + +#include <string.h> + +int main(int argc, char** argv) { +#if !defined(__clang__) + char buffer[8] = {0}; + strlcat(buffer, "1234567", sizeof(buffer)); + puts(buffer); + + CHK_FAIL_START + strlcat(buffer, "1234567890", 10); + CHK_FAIL_END + + puts(buffer); +#endif + return ret; +} diff --git a/tests/test_strlcpy_dynamic_write.c b/tests/test_strlcpy_dynamic_write.c @@ -0,0 +1,21 @@ +#define _GNU_SOURCE +#define _BSD_SOURCE + +#include "common.h" + +#include <string.h> + +int main(int argc, char** argv) { +#if !defined(__clang__) + char buffer[8] = {0}; + strlcpy(buffer, "1234567", sizeof(buffer)); + puts(buffer); + + CHK_FAIL_START + strlcpy(buffer, argv[1], argc); + CHK_FAIL_END + + puts(buffer); +#endif + return ret; +} diff --git a/tests/test_strlcpy_static_write.c b/tests/test_strlcpy_static_write.c @@ -0,0 +1,21 @@ +#define _GNU_SOURCE +#define _BSD_SOURCE + +#include "common.h" + +#include <string.h> + +int main(int argc, char** argv) { +#if !defined(__clang__) + char buffer[8] = {0}; + strlcpy(buffer, "1234567", sizeof(buffer)); + puts(buffer); + + CHK_FAIL_START + strlcpy(buffer, "1234567890", 10); + CHK_FAIL_END + + puts(buffer); +#endif + return ret; +} diff --git a/tests/test_strncat_dynamic_write.c b/tests/test_strncat_dynamic_write.c @@ -0,0 +1,18 @@ +#include "common.h" + +#include <string.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + strncat(buffer, "1234567", 5); + puts(buffer); + +#if 0 + CHK_FAIL_START + strncat(buffer, argv[1], argc); + CHK_FAIL_END +#endif + + puts(buffer); + return ret; +} diff --git a/tests/test_strncat_static_write.c b/tests/test_strncat_static_write.c @@ -0,0 +1,19 @@ +#include "common.h" + +#include <string.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + char src[] = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'}; + strncat(buffer, src, 5); + puts(buffer); + +#if 0 + CHK_FAIL_START + strncat(buffer, src, 10); + CHK_FAIL_END +#endif + + puts(buffer); + return ret; +} diff --git a/tests/test_strncpy_dynamic_write.c b/tests/test_strncpy_dynamic_write.c @@ -0,0 +1,18 @@ +#include "common.h" + +#include <string.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + char src[] = {'A', 'B', 'C', 'D', 'E', 'F'}; + + strncpy(buffer, src, 5); + puts(buffer); + + CHK_FAIL_START + strncpy(buffer, argv[1], argc); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_strncpy_static_write.c b/tests/test_strncpy_static_write.c @@ -0,0 +1,18 @@ +#include "common.h" + +#include <string.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + char src[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L'}; + + strncpy(buffer, src, 5); + puts(buffer); + + CHK_FAIL_START + strncpy(buffer, src, 10); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_swab_dynamic_read.c b/tests/test_swab_dynamic_read.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <unistd.h> + +int main(int argc, char** argv) { + char buffer[12] = {0}; + swab("1234567890", buffer, sizeof(buffer) - 1); + puts(buffer); + + CHK_FAIL_START + swab("123456", buffer, argc); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_swab_dynamic_write.c b/tests/test_swab_dynamic_write.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <unistd.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + swab("1234567890", buffer, sizeof(buffer) - 1); + puts(buffer); + + CHK_FAIL_START + swab("1234567890", buffer, argc); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_swab_static_read.c b/tests/test_swab_static_read.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <unistd.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + swab("123456", buffer, 4); + puts(buffer); + + CHK_FAIL_START + swab("123456", buffer, sizeof(buffer)); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_swab_static_write.c b/tests/test_swab_static_write.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <unistd.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + swab("1234567890", buffer, sizeof(buffer) - 1); + puts(buffer); + + CHK_FAIL_START + swab("1234567890", buffer, sizeof(buffer) + 1); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_ttyname_r_dynamic.c b/tests/test_ttyname_r_dynamic.c @@ -0,0 +1,14 @@ +#include "common.h" + +#include <unistd.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + + CHK_FAIL_START + ttyname_r(0, buffer, argc); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_ttyname_r_static.c b/tests/test_ttyname_r_static.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_vsnprintf_dynamic.c b/tests/test_vsnprintf_dynamic.c @@ -0,0 +1,29 @@ +#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); + return 0; +} + +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_static.c b/tests/test_vsnprintf_static.c @@ -0,0 +1,29 @@ +#include "common.h" + +#include <stdarg.h> +#include <unistd.h> + +char buffer[12] = {0}; + +int msg_valid(int n, const char * format, ... ) { + va_list args; + va_start (args, format); + vsnprintf(buffer, n, format, args); + va_end (args); + return 0; +} + +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(sizeof(buffer)+1, "%s", "1234567890ABCDEF"); +} diff --git a/tests/test_vsprintf.c b/tests/test_vsprintf.c @@ -0,0 +1,29 @@ +#include "common.h" + +#include <stdarg.h> +#include <unistd.h> + +char buffer[12] = {0}; + +int msg_valid(const char * format, ... ) { + va_list args; + va_start (args, format); + vsprintf(buffer, format, args); + va_end (args); + return 0; +} + +int msg(const char * format, ... ) { + va_list args; + va_start (args, format); + CHK_FAIL_START + vsprintf(buffer, format, args); + CHK_FAIL_END + va_end (args); + return ret; +} + +int main(int argc, char** argv) { + msg_valid("%s", "1234567"); + return msg("%s", "1234567890ABCDEF"); +} diff --git a/tests/test_wcscat_static_write.c b/tests/test_wcscat_static_write.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <wchar.h> + +int main(int argc, char** argv) { + wchar_t buffer[8] = {0}; + wcscat(buffer, L"α"); + printf("%ls\n", buffer); + + CHK_FAIL_START + wcscat(buffer, L"αβγδεζηθικλμνξοπρστυφχψω"); + CHK_FAIL_END + + printf("%ls\n", buffer); + return ret; +} diff --git a/tests/test_wcscpy_static_write.c b/tests/test_wcscpy_static_write.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <wchar.h> + +int main(int argc, char** argv) { + wchar_t buffer[8] = {0}; + wcscpy(buffer, L"α"); + printf("%ls\n", buffer); + + CHK_FAIL_START + wcscpy(buffer, L"αβγδεζηθικλμνξοπρστυφχψω"); + CHK_FAIL_END + + printf("%ls\n", buffer); + return ret; +} diff --git a/tests/test_wcsncat_static_write.c b/tests/test_wcsncat_static_write.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <wchar.h> + +int main(int argc, char** argv) { + wchar_t buffer[8] = {0}; + wcsncat(buffer, L"αβγδεζηθικλμνξοπρστυφχψω", 2); + printf("%ls\n", buffer); + + CHK_FAIL_START + wcsncat(buffer, L"αβγδεζηθικλμνξοπρστυφχψω", 1337); + CHK_FAIL_END + + printf("%ls\n", buffer); + return ret; +} diff --git a/tests/test_wcsncpy_static_write.c b/tests/test_wcsncpy_static_write.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <wchar.h> + +int main(int argc, char** argv) { + wchar_t buffer[8] = {0}; + wcsncpy(buffer, L"αβγδεζηθικλμνξοπρστυφχψω", 1); + printf("%ls\n", buffer); + + CHK_FAIL_START + wcsncpy(buffer, L"αβγδεζηθικλμνξοπρστυφχψω", 1337); + CHK_FAIL_END + + printf("%ls\n", buffer); + return ret; +} diff --git a/tests/test_wmemcpy_dynamic_write.c b/tests/test_wmemcpy_dynamic_write.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <wchar.h> + +int main(int argc, char** argv) { + wchar_t buffer[2] = {0}; + wmemcpy(buffer, L"αβγδεζηθικλμνξοπρστυφχψω", 2); + printf("%ls\n", buffer); + + CHK_FAIL_START + wmemcpy(buffer, L"αβγδεζηθικλμνξοπρστυφχψω", argc); + CHK_FAIL_END + + printf("%ls\n", buffer); + return ret; +} diff --git a/tests/test_wmemcpy_static_write.c b/tests/test_wmemcpy_static_write.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <wchar.h> + +int main(int argc, char** argv) { + wchar_t buffer[2] = {0}; + wmemcpy(buffer, L"αβγδεζηθικλμνξοπρστυφχψω", 2); + printf("%ls\n", buffer); + + CHK_FAIL_START + wmemcpy(buffer, L"αβγδεζηθικλμνξοπρστυφχψω", 1337); + CHK_FAIL_END + + printf("%ls\n", buffer); + return ret; +} diff --git a/tests/test_wmemmove_dynamic_write.c b/tests/test_wmemmove_dynamic_write.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <wchar.h> + +int main(int argc, char** argv) { + wchar_t buffer[2] = {0}; + wmemmove(buffer, L"αβγδεζηθικλμνξοπρστυφχψω", 2); + printf("%ls\n", buffer); + + CHK_FAIL_START + wmemmove(buffer, L"αβγδεζηθικλμνξοπρστυφχψω", argc); + CHK_FAIL_END + + printf("%ls\n", buffer); + return ret; +} diff --git a/tests/test_wmemmove_static_write.c b/tests/test_wmemmove_static_write.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <wchar.h> + +int main(int argc, char** argv) { + wchar_t buffer[2] = {0}; + wmemmove(buffer, L"αβγδεζηθικλμνξοπρστυφχψω", 2); + printf("%ls\n", buffer); + + CHK_FAIL_START + wmemmove(buffer, L"αβγδεζηθικλμνξοπρστυφχψω", 1337); + CHK_FAIL_END + + printf("%ls\n", buffer); + return ret; +} diff --git a/tests/test_wmemset_dynamic.c b/tests/test_wmemset_dynamic.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <wchar.h> + +int main(int argc, char** argv) { + wchar_t buffer[4] = {0}; + wmemset(buffer, L'A', 3); + printf("%ls\n", buffer); + + CHK_FAIL_START + wmemset(buffer, L'B', argc); + CHK_FAIL_END + + printf("%ls\n", buffer); + return ret; +} diff --git a/tests/test_wmemset_static.c b/tests/test_wmemset_static.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <wchar.h> + +int main(int argc, char** argv) { + wchar_t buffer[4] = {0}; + wmemset(buffer, L'A', 3); + printf("%ls\n", buffer); + + CHK_FAIL_START + wmemset(buffer, L'B', 16); + CHK_FAIL_END + + printf("%ls\n", buffer); + return ret; +} diff --git a/tests/test_write_dynamic.c b/tests/test_write_dynamic.c @@ -0,0 +1,14 @@ +#include "common.h" + +#include <unistd.h> + +int main(int argc, char** argv) { + char buffer[8] = {0}; + + CHK_FAIL_START + write(0, buffer, argc); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_write_static.c b/tests/test_write_static.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; +}