Skip to content

Commit 459d202

Browse files
nekopsykosejvoisin
authored andcommitted
prefix special defines with FORTIFY_
just in case, and because 'PEDANTIC_CHECKS' is a really generic name
1 parent 936d55d commit 459d202

File tree

4 files changed

+33
-33
lines changed

4 files changed

+33
-33
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ on Clang. It was initially intended to be used on
2424
- It has a [comprehensive suite of tests](https://github.com/jvoisin/fortify-headers/tree/master/tests),
2525
running both on Clang and on GCC for every commit, with
2626
[significant coverage](https://jvoisin.github.io/fortify-headers/)
27-
- Defining `USE_NATIVE_CHK` will make use of compiler-provided builtin `_chk`
27+
- Defining `FORTIFY_USE_NATIVE_CHK` will make use of compiler-provided builtin `_chk`
2828
functions, which might be a bit better in term of diagnostics,
2929
but won't necessarily provide the same amount of security checks.
30-
- Defining `PEDANTIC_CHECKS` will enable pedantic checks, that while technically
30+
- Defining `FORTIFY_PEDANTIC_CHECKS` will enable pedantic checks, that while technically
3131
correct, might break some programs relying on widely accepted
3232
undefined-behaviours.
3333

include/stdio.h

+10-10
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ __diagnose_as_builtin(__builtin_vsnprintf, 1, 2, 3, 4)
152152
_FORTIFY_FN(vsnprintf) int vsnprintf(char * _FORTIFY_POS0 __s, size_t __n,
153153
const char *__f, __builtin_va_list __v)
154154
{
155-
#if __has_builtin(__builtin___vsnprintf_chk) && USE_NATIVE_CHK
155+
#if __has_builtin(__builtin___vsnprintf_chk) && FORTIFY_USE_NATIVE_CHK
156156
return __builtin___vsnprintf_chk(__s, __n, _FORTIFY_SOURCE, __fh_bos(__s, 0), __f, __v);
157157
#else
158158
__fh_size_t __b = __fh_bos(__s, 0);
@@ -172,7 +172,7 @@ __diagnose_as_builtin(__builtin_vsprintf, 1, 2, 3)
172172
_FORTIFY_FN(vsprintf) int vsprintf(char * _FORTIFY_POS0 __s, const char *__f,
173173
__builtin_va_list __v)
174174
{
175-
#if __has_builtin(__builtin___vsprintf_chk) && USE_NATIVE_CHK
175+
#if __has_builtin(__builtin___vsprintf_chk) && FORTIFY_USE_NATIVE_CHK
176176
return __builtin___vsprintf_chk(__s, _FORTIFY_SOURCE, __fh_bos(__s, 0), __f, __v);
177177
#else
178178
__fh_size_t __b = __fh_bos(__s, 0);
@@ -200,7 +200,7 @@ __diagnose_as_builtin(__builtin_vfprintf, 2, 3)
200200
#endif
201201
_FORTIFY_FN(vfprintf) int vfprintf(FILE * __s, const char *__f, __builtin_va_list __v)
202202
{
203-
#if __has_builtin(__builtin___vfprintf_chk) && USE_NATIVE_CHK
203+
#if __has_builtin(__builtin___vfprintf_chk) && FORTIFY_USE_NATIVE_CHK
204204
return __builtin___vfprintf_chk(__s, _FORTIFY_SOURCE, __f, __v);
205205
#else
206206
return __orig_vfprintf(__s, __f, __v);
@@ -214,7 +214,7 @@ __diagnose_as_builtin(__builtin_vprintf, 1, 2)
214214
#endif
215215
_FORTIFY_FN(vprintf) int vprintf(const char *__f, __builtin_va_list __v)
216216
{
217-
#if __has_builtin(__builtin___vprintf_chk) && USE_NATIVE_CHK
217+
#if __has_builtin(__builtin___vprintf_chk) && FORTIFY_USE_NATIVE_CHK
218218
return __builtin___vprintf_chk(_FORTIFY_SOURCE, __f, __v);
219219
#else
220220
return __orig_vprintf(__f, __v);
@@ -228,7 +228,7 @@ __diagnose_as_builtin(__builtin_vasprintf, 1, 2, 3)
228228
#endif
229229
_FORTIFY_FN(vasprintf) int vasprintf(char **strp, const char *fmt, __builtin_va_list ap)
230230
{
231-
#if __has_builtin(__builtin___vasprintf_chk) && USE_NATIVE_CHK
231+
#if __has_builtin(__builtin___vasprintf_chk) && FORTIFY_USE_NATIVE_CHK
232232
return __builtin___vasprintf_chk(_FORTIFY_SOURCE, strp, fmt, ap);
233233
#else
234234
int ret = __orig_vasprintf(strp, fmt, ap);
@@ -274,7 +274,7 @@ __fh_format(printf, 3, 4)
274274
_FORTIFY_FN(snprintf) int snprintf(char *__s, size_t __n,
275275
const char *__f, ...)
276276
{
277-
#if __has_builtin(__builtin___snprintf_chk) && USE_NATIVE_CHK
277+
#if __has_builtin(__builtin___snprintf_chk) && FORTIFY_USE_NATIVE_CHK
278278
return __builtin___snprintf_chk(__s, __n, _FORTIFY_SOURCE, __fh_bos(__s, 0), __f, __builtin_va_arg_pack());
279279
#else
280280
__fh_size_t __b = __fh_bos(__s, 0);
@@ -290,7 +290,7 @@ __fh_access(read_write, 1)
290290
__fh_access(read_only, 2)
291291
_FORTIFY_FN(sprintf) int sprintf(char *__s, const char *__f, ...)
292292
{
293-
#if __has_builtin(__builtin___sprintf_chk) && USE_NATIVE_CHK
293+
#if __has_builtin(__builtin___sprintf_chk) && FORTIFY_USE_NATIVE_CHK
294294
return __builtin___sprintf_chk(__s, _FORTIFY_SOURCE, __fh_bos(__s, 0), __f, __builtin_va_arg_pack());
295295
#else
296296
__fh_size_t __b = __fh_bos(__s, 0);
@@ -311,7 +311,7 @@ __fh_format(printf, 1, 2)
311311
__fh_access(read_only, 1)
312312
_FORTIFY_FN(printf) int printf(const char *__f, ...)
313313
{
314-
#if __has_builtin(__builtin___printf_chk) && USE_NATIVE_CHK
314+
#if __has_builtin(__builtin___printf_chk) && FORTIFY_USE_NATIVE_CHK
315315
return __builtin___printf_chk(_FORTIFY_SOURCE, __f, __builtin_va_arg_pack());
316316
#else
317317
return __orig_printf(__f, __builtin_va_arg_pack());
@@ -325,7 +325,7 @@ __diagnose_as_builtin(__builtin_fprintf, 2, 3)
325325
#endif
326326
_FORTIFY_FN(fprintf) int fprintf(FILE *__s, const char *__f, ...)
327327
{
328-
#if __has_builtin(__builtin___fprintf_chk) && USE_NATIVE_CHK
328+
#if __has_builtin(__builtin___fprintf_chk) && FORTIFY_USE_NATIVE_CHK
329329
return __builtin___fprintf_chk(_FORTIFY_SOURCE, __s, __f, __builtin_va_arg_pack());
330330
#else
331331
return __orig_fprintf(__s, __f, __builtin_va_arg_pack());
@@ -342,7 +342,7 @@ __diagnose_as_builtin(__builtin_asprintf, 2, 3)
342342
#endif
343343
_FORTIFY_FN(asprintf) int asprintf(char **strp, const char *fmt, ...)
344344
{
345-
#if __has_builtin(__builtin___asprintf_chk) && USE_NATIVE_CHK
345+
#if __has_builtin(__builtin___asprintf_chk) && FORTIFY_USE_NATIVE_CHK
346346
return __builtin___asprintf_chk(_FORTIFY_SOURCE, strp, fmt, __builtin_va_arg_pack());
347347
#else
348348
int ret = __orig_asprintf(strp, fmt, __builtin_va_arg_pack());

include/string.h

+20-20
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ _FORTIFY_FN(memcpy) void *memcpy(void * _FORTIFY_POS0 __od,
4848
const void * _FORTIFY_POS0 __os, size_t __n)
4949
__error_if((__fh_bos(__od, 0) < __n), "'memcpy' called with `n` bigger than the size of `d`.")
5050
{
51-
#if __has_builtin(__builtin___memcpy_chk) && USE_NATIVE_CHK
51+
#if __has_builtin(__builtin___memcpy_chk) && FORTIFY_USE_NATIVE_CHK
5252
return __builtin___memcpy_chk(__od, __os, __n, __fh_bos(__od, 0));
5353
#else
54-
#if defined PEDANTIC_CHECKS
54+
#if defined FORTIFY_PEDANTIC_CHECKS
5555
if (!__od || !__os)
5656
__builtin_trap();
5757
#endif
@@ -75,10 +75,10 @@ __diagnose_as_builtin(__builtin_memmove, 1, 2, 3)
7575
_FORTIFY_FN(memmove) void *memmove(void * _FORTIFY_POS0 __d,
7676
const void * _FORTIFY_POS0 __s, size_t __n)
7777
{
78-
#if __has_builtin(__builtin___memmove_chk) && USE_NATIVE_CHK
78+
#if __has_builtin(__builtin___memmove_chk) && FORTIFY_USE_NATIVE_CHK
7979
return __builtin___memmove_chk(__d, __s, __n, __fh_bos(__d, 0));
8080
#else
81-
#if defined PEDANTIC_CHECKS
81+
#if defined FORTIFY_PEDANTIC_CHECKS
8282
if (!__d || !__s)
8383
__builtin_trap();
8484
#endif
@@ -99,10 +99,10 @@ __diagnose_as_builtin(__builtin_memset, 1, 2, 3)
9999
_FORTIFY_FN(memset) void *memset(void * _FORTIFY_POS0 __d, int __c, size_t __n)
100100
__warning_if(__c != 0 && __n == 0, "'memset' will set `0` bytes; did you invert the arguments?")
101101
{
102-
#if __has_builtin(__builtin___memset_chk) && USE_NATIVE_CHK
102+
#if __has_builtin(__builtin___memset_chk) && FORTIFY_USE_NATIVE_CHK
103103
return __builtin___memset_chk(__d, __c, __n, __fh_bos(__d, 0));
104104
#else
105-
#if defined PEDANTIC_CHECKS
105+
#if defined FORTIFY_PEDANTIC_CHECKS
106106
if (!__d)
107107
__builtin_trap();
108108
#endif
@@ -121,10 +121,10 @@ __diagnose_as_builtin(__builtin_memchr, 1, 2, 3)
121121
#endif
122122
_FORTIFY_FN(memchr) void *memchr(const void * _FORTIFY_POS0 __d, int __c, size_t __n)
123123
{
124-
#if __has_builtin(__builtin___memchr_chk) && USE_NATIVE_CHK
124+
#if __has_builtin(__builtin___memchr_chk) && FORTIFY_USE_NATIVE_CHK
125125
return __builtin___memchr_chk(__d, __c, __n, __fh_bos(__d, 0));
126126
#else
127-
#if defined PEDANTIC_CHECKS
127+
#if defined FORTIFY_PEDANTIC_CHECKS
128128
if (!__d)
129129
__builtin_trap();
130130
#if __STDC_VERSION__ < 201112L
@@ -142,7 +142,7 @@ _FORTIFY_FN(memchr) void *memchr(const void * _FORTIFY_POS0 __d, int __c, size_t
142142
__fh_access(read_only, 1, 2)
143143
_FORTIFY_FN(strchr) char *strchr(const char * _FORTIFY_POS0 __s, int __c)
144144
{
145-
#if __has_builtin(__builtin___strchr_chk) && USE_NATIVE_CHK
145+
#if __has_builtin(__builtin___strchr_chk) && FORTIFY_USE_NATIVE_CHK
146146
return __builtin___strchr_chk(__s, __c, __fh_bos(__s, 0));
147147
#else
148148
__fh_size_t __b = __fh_bos(__s, 0);
@@ -157,7 +157,7 @@ _FORTIFY_FN(strchr) char *strchr(const char * _FORTIFY_POS0 __s, int __c)
157157
__fh_access(read_only, 1, 2)
158158
_FORTIFY_FN(strrchr) char *strrchr(const char * _FORTIFY_POS0 __s, int __c)
159159
{
160-
#if __has_builtin(__builtin___strrchr_chk) && USE_NATIVE_CHK
160+
#if __has_builtin(__builtin___strrchr_chk) && FORTIFY_USE_NATIVE_CHK
161161
return __builtin___strrchr_chk(__s, __c, __fh_bos(__s, 0));
162162
#else
163163
__fh_size_t __b = __fh_bos(__s, 0);
@@ -181,7 +181,7 @@ __diagnose_as_builtin(__builtin_stpcpy, 1, 2)
181181
#endif
182182
_FORTIFY_FN(stpcpy) char *stpcpy(char * _FORTIFY_POS0 __d, const char *__s)
183183
{
184-
#if __has_builtin(__builtin___stpcpy_chk) && USE_NATIVE_CHK
184+
#if __has_builtin(__builtin___stpcpy_chk) && FORTIFY_USE_NATIVE_CHK
185185
return __builtin___stpcpy_chk(__d, __s, __fh_bos(__d, 0));
186186
#else
187187
__fh_size_t __n = strlen(__s) + 1;
@@ -205,7 +205,7 @@ __diagnose_as_builtin(__builtin_stpncpy, 1, 2, 3)
205205
_FORTIFY_FN(stpncpy) char *stpncpy(char * _FORTIFY_POS0 __d, const char *__s,
206206
size_t __n)
207207
{
208-
#if __has_builtin(__builtin___stpncpy_chk) && USE_NATIVE_CHK
208+
#if __has_builtin(__builtin___stpncpy_chk) && FORTIFY_USE_NATIVE_CHK
209209
return __builtin___stpncpy_chk(__d, __s, __n, __fh_bos(__d, 0));
210210
#else
211211
__fh_size_t max_len_s = strnlen(__s, __n);
@@ -231,7 +231,7 @@ __diagnose_as_builtin(__builtin_strcat, 1, 2)
231231
#endif
232232
_FORTIFY_FN(strcat) char *strcat(char * _FORTIFY_POS0 __d, const char *__s)
233233
{
234-
#if __has_builtin(__builtin___strcat_chk) && USE_NATIVE_CHK
234+
#if __has_builtin(__builtin___strcat_chk) && FORTIFY_USE_NATIVE_CHK
235235
return __builtin___strcat_chk(__d, __s, __fh_bos(__d, 0));
236236
#else
237237
__fh_size_t __b = __fh_bos(__d, 0);
@@ -249,7 +249,7 @@ __diagnose_as_builtin(__builtin_strcpy, 1, 2)
249249
#endif
250250
_FORTIFY_FN(strcpy) char *strcpy(char * _FORTIFY_POS0 __d, const char *__s)
251251
{
252-
#if __has_builtin(__builtin___strcpy_chk) && USE_NATIVE_CHK
252+
#if __has_builtin(__builtin___strcpy_chk) && FORTIFY_USE_NATIVE_CHK
253253
return __builtin___strcpy_chk(__d, __s, __fh_bos(__d, 0));
254254
#else
255255
__fh_size_t __n = strlen(__s) + 1;
@@ -270,7 +270,7 @@ __diagnose_as_builtin(__builtin_strlen, 1)
270270
#endif
271271
_FORTIFY_FN(strlen) size_t strlen(const char * _FORTIFY_POS0 __s)
272272
{
273-
#if __has_builtin(__builtin___strlen_chk) && USE_NATIVE_CHK
273+
#if __has_builtin(__builtin___strlen_chk) && FORTIFY_USE_NATIVE_CHK
274274
return __builtin___strlen_chk(__s, __fh_bos(__s, 0));
275275
#else
276276
__fh_size_t ret = __orig_strlen(__s);
@@ -288,7 +288,7 @@ __diagnose_as_builtin(__builtin_strncat, 1, 2, 3)
288288
_FORTIFY_FN(strncat) char *strncat(char * _FORTIFY_POS0 __d, const char *__s,
289289
size_t __n)
290290
{
291-
#if __has_builtin(__builtin___strncat_chk) && USE_NATIVE_CHK
291+
#if __has_builtin(__builtin___strncat_chk) && FORTIFY_USE_NATIVE_CHK
292292
return __builtin___strncat_chk(__d, __s, __n, __fh_bos(__d, 0));
293293
#else
294294
__fh_size_t __b = __fh_bos(__d, 0);
@@ -311,7 +311,7 @@ __diagnose_as_builtin(__builtin_strncpy, 1, 2, 3)
311311
_FORTIFY_FN(strncpy) char *strncpy(char * _FORTIFY_POS0 __d,
312312
const char *__s, size_t __n)
313313
{
314-
#if __has_builtin(__builtin___strncpy_chk) && USE_NATIVE_CHK
314+
#if __has_builtin(__builtin___strncpy_chk) && FORTIFY_USE_NATIVE_CHK
315315
return __builtin___strncpy_chk(__d, __s, __n, __fh_bos(__d, 0));
316316
#else
317317
__fh_size_t max_len_s = strnlen(__s, __n);
@@ -338,7 +338,7 @@ __diagnose_as_builtin(__builtin_mempcpy, 1, 2, 3)
338338
_FORTIFY_FN(mempcpy) void *mempcpy(void * _FORTIFY_POS0 __d,
339339
const void * _FORTIFY_POS0 __s, size_t __n)
340340
{
341-
#if __has_builtin(__builtin___mempcpy_chk) && USE_NATIVE_CHK
341+
#if __has_builtin(__builtin___mempcpy_chk) && FORTIFY_USE_NATIVE_CHK
342342
return __builtin___mempcpy_chk(__d, __s, __n, __fh_bos(__d, 0));
343343
#else
344344
if (!__d || !__s)
@@ -365,7 +365,7 @@ __diagnose_as_builtin(__builtin_strlcat, 1, 2, 3)
365365
_FORTIFY_FN(strlcat) size_t strlcat(char * _FORTIFY_POS0 __d,
366366
const char *__s, size_t __n)
367367
{
368-
#if __has_builtin(__builtin___strlcat_chk) && USE_NATIVE_CHK
368+
#if __has_builtin(__builtin___strlcat_chk) && FORTIFY_USE_NATIVE_CHK
369369
return __builtin___strlcat_chk(__d, __s, __n, __fh_bos(__d, 0));
370370
#else
371371
__fh_size_t __b = __fh_bos(__d, 0);
@@ -384,7 +384,7 @@ __diagnose_as_builtin(__builtin_strlcpy, 1, 2, 3)
384384
_FORTIFY_FN(strlcpy) size_t strlcpy(char * _FORTIFY_POS0 __d,
385385
const char *__s, size_t __n)
386386
{
387-
#if __has_builtin(__builtin___strlcpy_chk) && USE_NATIVE_CHK
387+
#if __has_builtin(__builtin___strlcpy_chk) && FORTIFY_USE_NATIVE_CHK
388388
return __builtin___strlcpy_chk(__d, __s, __n, __fh_bos(__d, 0));
389389
#else
390390
__fh_size_t __b = __fh_bos(__d, 0);

tests/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CFLAGS+=-I../include/ -D_FORTIFY_SOURCE=3 -static -O2 -DPEDANTIC_CHECKS -Wno-format -Werror=pointer-arith
1+
CFLAGS+=-I../include/ -D_FORTIFY_SOURCE=3 -static -O2 -DFORTIFY_PEDANTIC_CHECKS -Wno-format -Werror=pointer-arith
22

33
COMPTIME_TARGETS= \
44
test_memcpy_overwrite_under \

0 commit comments

Comments
 (0)