fortify-headers

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

commit 76fef96b2b29fc90cdfea3e595ab98d267c6b965
parent 160298c6fb4c5151ef58ef1556ae2c271d8a9a9e
Author: jvoisin <julien.voisin@dustri.org>
Date:   Sat, 30 Sep 2023 20:24:58 +0200

Add `vprintf`

Diffstat:
Minclude/stdio.h | 19++++++++++++++++++-
Mtests/Makefile | 1+
Atests/test_vprintf.c | 16++++++++++++++++
3 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/include/stdio.h b/include/stdio.h @@ -36,9 +36,10 @@ extern "C" { #undef fread #undef fwrite #undef popen +#undef printf +#undef vprintf #undef vsnprintf #undef vsprintf -#undef printf __access(read_only, 2) #if __has_builtin(__builtin_fdopen) @@ -183,6 +184,22 @@ _FORTIFY_FN(vsprintf) int vsprintf(char * _FORTIFY_POS0 __s, const char *__f, #endif } +#ifndef __clang__ /* FIXME */ +__access(read_only, 1) +__format(printf, 1, 0) +#if __has_builtin(__builtin_vprintf) +__diagnose_as_builtin(__builtin_vprintf, 1, 2) +#endif +_FORTIFY_FN(vprintf) int vprintf(const char *__f, __builtin_va_list __v) +{ +#if __has_builtin(__builtin___vprintf_chk) && USE_NATIVE_CHK + return __builtin___vprintf_chk(_FORTIFY_SOURCE, __f, __v); +#else + return __orig_vprintf(__f, __v); +#endif +} +#endif + #if __has_builtin(__builtin_va_arg_pack) diff --git a/tests/Makefile b/tests/Makefile @@ -113,6 +113,7 @@ RUNTIME_TARGETS= \ test_vsnprintf_dynamic \ test_vsnprintf_static \ test_vsprintf \ + test_vprintf \ test_wcscat_static_write \ test_wcscpy_static_write \ test_wcsncat_static_write \ diff --git a/tests/test_vprintf.c b/tests/test_vprintf.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); + vprintf(format, args); + va_end(args); +} + + +int main(int argc, char** argv) { + wrap("%s", "1234567"); +}