commit 459d202b1bbf7abb817a596ce9374edfb7b4da8f
parent 936d55d4c263264bc21ccdaeed2537ff0d4320f2
Author: psykose <alice@ayaya.dev>
Date: Wed, 10 Jul 2024 06:49:02 +0200
prefix special defines with FORTIFY_
just in case, and because 'PEDANTIC_CHECKS' is a really generic name
Diffstat:
4 files changed, 33 insertions(+), 33 deletions(-)
diff --git a/README.md b/README.md
@@ -24,10 +24,10 @@ on Clang. It was initially intended to be used on
- It has a [comprehensive suite of tests](https://github.com/jvoisin/fortify-headers/tree/master/tests),
running both on Clang and on GCC for every commit, with
[significant coverage](https://jvoisin.github.io/fortify-headers/)
-- Defining `USE_NATIVE_CHK` will make use of compiler-provided builtin `_chk`
+- Defining `FORTIFY_USE_NATIVE_CHK` will make use of compiler-provided builtin `_chk`
functions, which might be a bit better in term of diagnostics,
but won't necessarily provide the same amount of security checks.
-- Defining `PEDANTIC_CHECKS` will enable pedantic checks, that while technically
+- Defining `FORTIFY_PEDANTIC_CHECKS` will enable pedantic checks, that while technically
correct, might break some programs relying on widely accepted
undefined-behaviours.
diff --git a/include/stdio.h b/include/stdio.h
@@ -152,7 +152,7 @@ __diagnose_as_builtin(__builtin_vsnprintf, 1, 2, 3, 4)
_FORTIFY_FN(vsnprintf) int vsnprintf(char * _FORTIFY_POS0 __s, size_t __n,
const char *__f, __builtin_va_list __v)
{
-#if __has_builtin(__builtin___vsnprintf_chk) && USE_NATIVE_CHK
+#if __has_builtin(__builtin___vsnprintf_chk) && FORTIFY_USE_NATIVE_CHK
return __builtin___vsnprintf_chk(__s, __n, _FORTIFY_SOURCE, __fh_bos(__s, 0), __f, __v);
#else
__fh_size_t __b = __fh_bos(__s, 0);
@@ -172,7 +172,7 @@ __diagnose_as_builtin(__builtin_vsprintf, 1, 2, 3)
_FORTIFY_FN(vsprintf) int vsprintf(char * _FORTIFY_POS0 __s, const char *__f,
__builtin_va_list __v)
{
-#if __has_builtin(__builtin___vsprintf_chk) && USE_NATIVE_CHK
+#if __has_builtin(__builtin___vsprintf_chk) && FORTIFY_USE_NATIVE_CHK
return __builtin___vsprintf_chk(__s, _FORTIFY_SOURCE, __fh_bos(__s, 0), __f, __v);
#else
__fh_size_t __b = __fh_bos(__s, 0);
@@ -200,7 +200,7 @@ __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
+#if __has_builtin(__builtin___vfprintf_chk) && FORTIFY_USE_NATIVE_CHK
return __builtin___vfprintf_chk(__s, _FORTIFY_SOURCE, __f, __v);
#else
return __orig_vfprintf(__s, __f, __v);
@@ -214,7 +214,7 @@ __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
+#if __has_builtin(__builtin___vprintf_chk) && FORTIFY_USE_NATIVE_CHK
return __builtin___vprintf_chk(_FORTIFY_SOURCE, __f, __v);
#else
return __orig_vprintf(__f, __v);
@@ -228,7 +228,7 @@ __diagnose_as_builtin(__builtin_vasprintf, 1, 2, 3)
#endif
_FORTIFY_FN(vasprintf) int vasprintf(char **strp, const char *fmt, __builtin_va_list ap)
{
-#if __has_builtin(__builtin___vasprintf_chk) && USE_NATIVE_CHK
+#if __has_builtin(__builtin___vasprintf_chk) && FORTIFY_USE_NATIVE_CHK
return __builtin___vasprintf_chk(_FORTIFY_SOURCE, strp, fmt, ap);
#else
int ret = __orig_vasprintf(strp, fmt, ap);
@@ -274,7 +274,7 @@ __fh_format(printf, 3, 4)
_FORTIFY_FN(snprintf) int snprintf(char *__s, size_t __n,
const char *__f, ...)
{
-#if __has_builtin(__builtin___snprintf_chk) && USE_NATIVE_CHK
+#if __has_builtin(__builtin___snprintf_chk) && FORTIFY_USE_NATIVE_CHK
return __builtin___snprintf_chk(__s, __n, _FORTIFY_SOURCE, __fh_bos(__s, 0), __f, __builtin_va_arg_pack());
#else
__fh_size_t __b = __fh_bos(__s, 0);
@@ -290,7 +290,7 @@ __fh_access(read_write, 1)
__fh_access(read_only, 2)
_FORTIFY_FN(sprintf) int sprintf(char *__s, const char *__f, ...)
{
-#if __has_builtin(__builtin___sprintf_chk) && USE_NATIVE_CHK
+#if __has_builtin(__builtin___sprintf_chk) && FORTIFY_USE_NATIVE_CHK
return __builtin___sprintf_chk(__s, _FORTIFY_SOURCE, __fh_bos(__s, 0), __f, __builtin_va_arg_pack());
#else
__fh_size_t __b = __fh_bos(__s, 0);
@@ -311,7 +311,7 @@ __fh_format(printf, 1, 2)
__fh_access(read_only, 1)
_FORTIFY_FN(printf) int printf(const char *__f, ...)
{
-#if __has_builtin(__builtin___printf_chk) && USE_NATIVE_CHK
+#if __has_builtin(__builtin___printf_chk) && FORTIFY_USE_NATIVE_CHK
return __builtin___printf_chk(_FORTIFY_SOURCE, __f, __builtin_va_arg_pack());
#else
return __orig_printf(__f, __builtin_va_arg_pack());
@@ -325,7 +325,7 @@ __diagnose_as_builtin(__builtin_fprintf, 2, 3)
#endif
_FORTIFY_FN(fprintf) int fprintf(FILE *__s, const char *__f, ...)
{
-#if __has_builtin(__builtin___fprintf_chk) && USE_NATIVE_CHK
+#if __has_builtin(__builtin___fprintf_chk) && FORTIFY_USE_NATIVE_CHK
return __builtin___fprintf_chk(_FORTIFY_SOURCE, __s, __f, __builtin_va_arg_pack());
#else
return __orig_fprintf(__s, __f, __builtin_va_arg_pack());
@@ -342,7 +342,7 @@ __diagnose_as_builtin(__builtin_asprintf, 2, 3)
#endif
_FORTIFY_FN(asprintf) int asprintf(char **strp, const char *fmt, ...)
{
-#if __has_builtin(__builtin___asprintf_chk) && USE_NATIVE_CHK
+#if __has_builtin(__builtin___asprintf_chk) && FORTIFY_USE_NATIVE_CHK
return __builtin___asprintf_chk(_FORTIFY_SOURCE, strp, fmt, __builtin_va_arg_pack());
#else
int ret = __orig_asprintf(strp, fmt, __builtin_va_arg_pack());
diff --git a/include/string.h b/include/string.h
@@ -48,10 +48,10 @@ _FORTIFY_FN(memcpy) void *memcpy(void * _FORTIFY_POS0 __od,
const void * _FORTIFY_POS0 __os, size_t __n)
__error_if((__fh_bos(__od, 0) < __n), "'memcpy' called with `n` bigger than the size of `d`.")
{
-#if __has_builtin(__builtin___memcpy_chk) && USE_NATIVE_CHK
+#if __has_builtin(__builtin___memcpy_chk) && FORTIFY_USE_NATIVE_CHK
return __builtin___memcpy_chk(__od, __os, __n, __fh_bos(__od, 0));
#else
-#if defined PEDANTIC_CHECKS
+#if defined FORTIFY_PEDANTIC_CHECKS
if (!__od || !__os)
__builtin_trap();
#endif
@@ -75,10 +75,10 @@ __diagnose_as_builtin(__builtin_memmove, 1, 2, 3)
_FORTIFY_FN(memmove) void *memmove(void * _FORTIFY_POS0 __d,
const void * _FORTIFY_POS0 __s, size_t __n)
{
-#if __has_builtin(__builtin___memmove_chk) && USE_NATIVE_CHK
+#if __has_builtin(__builtin___memmove_chk) && FORTIFY_USE_NATIVE_CHK
return __builtin___memmove_chk(__d, __s, __n, __fh_bos(__d, 0));
#else
-#if defined PEDANTIC_CHECKS
+#if defined FORTIFY_PEDANTIC_CHECKS
if (!__d || !__s)
__builtin_trap();
#endif
@@ -99,10 +99,10 @@ __diagnose_as_builtin(__builtin_memset, 1, 2, 3)
_FORTIFY_FN(memset) void *memset(void * _FORTIFY_POS0 __d, int __c, size_t __n)
__warning_if(__c != 0 && __n == 0, "'memset' will set `0` bytes; did you invert the arguments?")
{
-#if __has_builtin(__builtin___memset_chk) && USE_NATIVE_CHK
+#if __has_builtin(__builtin___memset_chk) && FORTIFY_USE_NATIVE_CHK
return __builtin___memset_chk(__d, __c, __n, __fh_bos(__d, 0));
#else
-#if defined PEDANTIC_CHECKS
+#if defined FORTIFY_PEDANTIC_CHECKS
if (!__d)
__builtin_trap();
#endif
@@ -121,10 +121,10 @@ __diagnose_as_builtin(__builtin_memchr, 1, 2, 3)
#endif
_FORTIFY_FN(memchr) void *memchr(const void * _FORTIFY_POS0 __d, int __c, size_t __n)
{
-#if __has_builtin(__builtin___memchr_chk) && USE_NATIVE_CHK
+#if __has_builtin(__builtin___memchr_chk) && FORTIFY_USE_NATIVE_CHK
return __builtin___memchr_chk(__d, __c, __n, __fh_bos(__d, 0));
#else
-#if defined PEDANTIC_CHECKS
+#if defined FORTIFY_PEDANTIC_CHECKS
if (!__d)
__builtin_trap();
#if __STDC_VERSION__ < 201112L
@@ -142,7 +142,7 @@ _FORTIFY_FN(memchr) void *memchr(const void * _FORTIFY_POS0 __d, int __c, size_t
__fh_access(read_only, 1, 2)
_FORTIFY_FN(strchr) char *strchr(const char * _FORTIFY_POS0 __s, int __c)
{
-#if __has_builtin(__builtin___strchr_chk) && USE_NATIVE_CHK
+#if __has_builtin(__builtin___strchr_chk) && FORTIFY_USE_NATIVE_CHK
return __builtin___strchr_chk(__s, __c, __fh_bos(__s, 0));
#else
__fh_size_t __b = __fh_bos(__s, 0);
@@ -157,7 +157,7 @@ _FORTIFY_FN(strchr) char *strchr(const char * _FORTIFY_POS0 __s, int __c)
__fh_access(read_only, 1, 2)
_FORTIFY_FN(strrchr) char *strrchr(const char * _FORTIFY_POS0 __s, int __c)
{
-#if __has_builtin(__builtin___strrchr_chk) && USE_NATIVE_CHK
+#if __has_builtin(__builtin___strrchr_chk) && FORTIFY_USE_NATIVE_CHK
return __builtin___strrchr_chk(__s, __c, __fh_bos(__s, 0));
#else
__fh_size_t __b = __fh_bos(__s, 0);
@@ -181,7 +181,7 @@ __diagnose_as_builtin(__builtin_stpcpy, 1, 2)
#endif
_FORTIFY_FN(stpcpy) char *stpcpy(char * _FORTIFY_POS0 __d, const char *__s)
{
-#if __has_builtin(__builtin___stpcpy_chk) && USE_NATIVE_CHK
+#if __has_builtin(__builtin___stpcpy_chk) && FORTIFY_USE_NATIVE_CHK
return __builtin___stpcpy_chk(__d, __s, __fh_bos(__d, 0));
#else
__fh_size_t __n = strlen(__s) + 1;
@@ -205,7 +205,7 @@ __diagnose_as_builtin(__builtin_stpncpy, 1, 2, 3)
_FORTIFY_FN(stpncpy) char *stpncpy(char * _FORTIFY_POS0 __d, const char *__s,
size_t __n)
{
-#if __has_builtin(__builtin___stpncpy_chk) && USE_NATIVE_CHK
+#if __has_builtin(__builtin___stpncpy_chk) && FORTIFY_USE_NATIVE_CHK
return __builtin___stpncpy_chk(__d, __s, __n, __fh_bos(__d, 0));
#else
__fh_size_t max_len_s = strnlen(__s, __n);
@@ -231,7 +231,7 @@ __diagnose_as_builtin(__builtin_strcat, 1, 2)
#endif
_FORTIFY_FN(strcat) char *strcat(char * _FORTIFY_POS0 __d, const char *__s)
{
-#if __has_builtin(__builtin___strcat_chk) && USE_NATIVE_CHK
+#if __has_builtin(__builtin___strcat_chk) && FORTIFY_USE_NATIVE_CHK
return __builtin___strcat_chk(__d, __s, __fh_bos(__d, 0));
#else
__fh_size_t __b = __fh_bos(__d, 0);
@@ -249,7 +249,7 @@ __diagnose_as_builtin(__builtin_strcpy, 1, 2)
#endif
_FORTIFY_FN(strcpy) char *strcpy(char * _FORTIFY_POS0 __d, const char *__s)
{
-#if __has_builtin(__builtin___strcpy_chk) && USE_NATIVE_CHK
+#if __has_builtin(__builtin___strcpy_chk) && FORTIFY_USE_NATIVE_CHK
return __builtin___strcpy_chk(__d, __s, __fh_bos(__d, 0));
#else
__fh_size_t __n = strlen(__s) + 1;
@@ -270,7 +270,7 @@ __diagnose_as_builtin(__builtin_strlen, 1)
#endif
_FORTIFY_FN(strlen) size_t strlen(const char * _FORTIFY_POS0 __s)
{
-#if __has_builtin(__builtin___strlen_chk) && USE_NATIVE_CHK
+#if __has_builtin(__builtin___strlen_chk) && FORTIFY_USE_NATIVE_CHK
return __builtin___strlen_chk(__s, __fh_bos(__s, 0));
#else
__fh_size_t ret = __orig_strlen(__s);
@@ -288,7 +288,7 @@ __diagnose_as_builtin(__builtin_strncat, 1, 2, 3)
_FORTIFY_FN(strncat) char *strncat(char * _FORTIFY_POS0 __d, const char *__s,
size_t __n)
{
-#if __has_builtin(__builtin___strncat_chk) && USE_NATIVE_CHK
+#if __has_builtin(__builtin___strncat_chk) && FORTIFY_USE_NATIVE_CHK
return __builtin___strncat_chk(__d, __s, __n, __fh_bos(__d, 0));
#else
__fh_size_t __b = __fh_bos(__d, 0);
@@ -311,7 +311,7 @@ __diagnose_as_builtin(__builtin_strncpy, 1, 2, 3)
_FORTIFY_FN(strncpy) char *strncpy(char * _FORTIFY_POS0 __d,
const char *__s, size_t __n)
{
-#if __has_builtin(__builtin___strncpy_chk) && USE_NATIVE_CHK
+#if __has_builtin(__builtin___strncpy_chk) && FORTIFY_USE_NATIVE_CHK
return __builtin___strncpy_chk(__d, __s, __n, __fh_bos(__d, 0));
#else
__fh_size_t max_len_s = strnlen(__s, __n);
@@ -338,7 +338,7 @@ __diagnose_as_builtin(__builtin_mempcpy, 1, 2, 3)
_FORTIFY_FN(mempcpy) void *mempcpy(void * _FORTIFY_POS0 __d,
const void * _FORTIFY_POS0 __s, size_t __n)
{
-#if __has_builtin(__builtin___mempcpy_chk) && USE_NATIVE_CHK
+#if __has_builtin(__builtin___mempcpy_chk) && FORTIFY_USE_NATIVE_CHK
return __builtin___mempcpy_chk(__d, __s, __n, __fh_bos(__d, 0));
#else
if (!__d || !__s)
@@ -365,7 +365,7 @@ __diagnose_as_builtin(__builtin_strlcat, 1, 2, 3)
_FORTIFY_FN(strlcat) size_t strlcat(char * _FORTIFY_POS0 __d,
const char *__s, size_t __n)
{
-#if __has_builtin(__builtin___strlcat_chk) && USE_NATIVE_CHK
+#if __has_builtin(__builtin___strlcat_chk) && FORTIFY_USE_NATIVE_CHK
return __builtin___strlcat_chk(__d, __s, __n, __fh_bos(__d, 0));
#else
__fh_size_t __b = __fh_bos(__d, 0);
@@ -384,7 +384,7 @@ __diagnose_as_builtin(__builtin_strlcpy, 1, 2, 3)
_FORTIFY_FN(strlcpy) size_t strlcpy(char * _FORTIFY_POS0 __d,
const char *__s, size_t __n)
{
-#if __has_builtin(__builtin___strlcpy_chk) && USE_NATIVE_CHK
+#if __has_builtin(__builtin___strlcpy_chk) && FORTIFY_USE_NATIVE_CHK
return __builtin___strlcpy_chk(__d, __s, __n, __fh_bos(__d, 0));
#else
__fh_size_t __b = __fh_bos(__d, 0);
diff --git a/tests/Makefile b/tests/Makefile
@@ -1,4 +1,4 @@
-CFLAGS+=-I../include/ -D_FORTIFY_SOURCE=3 -static -O2 -DPEDANTIC_CHECKS -Wno-format -Werror=pointer-arith
+CFLAGS+=-I../include/ -D_FORTIFY_SOURCE=3 -static -O2 -DFORTIFY_PEDANTIC_CHECKS -Wno-format -Werror=pointer-arith
COMPTIME_TARGETS= \
test_memcpy_overwrite_under \