fortify-headers

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

commit 32b21b7d85383df49030b18240c1409e73001066
parent 6a801d8a749da3889ec57030cee09d1d60b4663e
Author: jvoisin <julien.voisin@dustri.org>
Date:   Sun,  1 Oct 2023 22:06:17 +0200

Add vfprintf`

Diffstat:
Minclude/stdio.h | 16++++++++++++++++
Mtests/Makefile | 1+
Atests/test_fprintf.c | 7+++++++
Atests/test_vfprintf.c | 16++++++++++++++++
4 files changed, 40 insertions(+), 0 deletions(-)

diff --git a/include/stdio.h b/include/stdio.h @@ -183,7 +183,23 @@ _FORTIFY_FN(vsprintf) int vsprintf(char * _FORTIFY_POS0 __s, const char *__f, } #ifndef __clang__ /* FIXME */ +#undef vfprintf #undef vprintf + +__access(read_only, 2) +__format(printf, 2, 0) +#if __has_builtin(__builtin_vfprintf) +__diagnose_as_builtin(__builtin_vfprintf, 2, 3) +#endif +_FORTIFY_FN(vfprintf) int vfprintf(FILE * __s, const char *__f, __builtin_va_list __v) +{ +#if __has_builtin(__builtin___vfprintf_chk) && USE_NATIVE_CHK + return __builtin___vfprintf_chk(__s, _FORTIFY_SOURCE, __f, __v); +#else + return __orig_vfprintf(__s, __f, __v); +#endif +} + __access(read_only, 1) __format(printf, 1, 0) #if __has_builtin(__builtin_vprintf) diff --git a/tests/Makefile b/tests/Makefile @@ -114,6 +114,7 @@ RUNTIME_TARGETS= \ test_vsnprintf_dynamic \ test_vsnprintf_static \ test_vsprintf \ + test_vfprintf \ test_vprintf \ test_wcscat_static_write \ test_wcscpy_static_write \ diff --git a/tests/test_fprintf.c b/tests/test_fprintf.c @@ -0,0 +1,7 @@ +#include "common.h" + +#include <stdio.h> + +int main(int argc, char** argv) { + fprintf(stdout, "%s", "1234567"); +} diff --git a/tests/test_vfprintf.c b/tests/test_vfprintf.c @@ -0,0 +1,16 @@ +#include "common.h" + +#include <stdarg.h> +#include <stdio.h> + +void wrap(char *format, ...) { + va_list args; + va_start(args, format); + vfprintf(stdout, format, args); + va_end(args); +} + + +int main(int argc, char** argv) { + wrap("%s", "1234567"); +}