|
| 1 | +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Hauke Mehrtens < [email protected]> |
| 3 | +Date: Sun, 26 Oct 2025 17:38:41 +0100 |
| 4 | +Subject: Check if FORTIFY_USE_NATIVE_CHK is defined |
| 5 | + |
| 6 | +The previews code tried to get the value defined for |
| 7 | +FORTIFY_USE_NATIVE_CHK and this resulted in some build errors like |
| 8 | +this: |
| 9 | +``` |
| 10 | +/include/fortify/stdio.h: In function 'vsnprintf': |
| 11 | +/include/fortify/stdio.h:155:49: error: "FORTIFY_USE_NATIVE_CHK" is not defined, evaluates to 0 [-Werror=undef] |
| 12 | + 155 | #if __has_builtin(__builtin___vsnprintf_chk) && FORTIFY_USE_NATIVE_CHK |
| 13 | + | ^~~~~~~~~~~~~~~~~~~~~~ |
| 14 | +``` |
| 15 | + |
| 16 | +Check if it is defined instead. |
| 17 | + |
| 18 | +Signed-off-by: Hauke Mehrtens < [email protected]> |
| 19 | +--- |
| 20 | + include/stdio.h | 20 ++++++++++---------- |
| 21 | + include/string.h | 32 ++++++++++++++++---------------- |
| 22 | + 2 files changed, 26 insertions(+), 26 deletions(-) |
| 23 | + |
| 24 | +--- a/include/stdio.h |
| 25 | ++++ b/include/stdio.h |
| 26 | +@@ -152,7 +152,7 @@ __diagnose_as_builtin(__builtin_vsnprint |
| 27 | + _FORTIFY_FN(vsnprintf) int vsnprintf(char * _FORTIFY_POS0 __s, size_t __n, |
| 28 | + const char *__f, __builtin_va_list __v) |
| 29 | + { |
| 30 | +-#if __has_builtin(__builtin___vsnprintf_chk) && FORTIFY_USE_NATIVE_CHK |
| 31 | ++#if __has_builtin(__builtin___vsnprintf_chk) && defined(FORTIFY_USE_NATIVE_CHK) |
| 32 | + return __builtin___vsnprintf_chk(__s, __n, _FORTIFY_SOURCE, __fh_bos(__s, 0), __f, __v); |
| 33 | + #else |
| 34 | + __fh_size_t __b = __fh_bos(__s, 0); |
| 35 | +@@ -172,7 +172,7 @@ __diagnose_as_builtin(__builtin_vsprintf |
| 36 | + _FORTIFY_FN(vsprintf) int vsprintf(char * _FORTIFY_POS0 __s, const char *__f, |
| 37 | + __builtin_va_list __v) |
| 38 | + { |
| 39 | +-#if __has_builtin(__builtin___vsprintf_chk) && FORTIFY_USE_NATIVE_CHK |
| 40 | ++#if __has_builtin(__builtin___vsprintf_chk) && defined(FORTIFY_USE_NATIVE_CHK) |
| 41 | + return __builtin___vsprintf_chk(__s, _FORTIFY_SOURCE, __fh_bos(__s, 0), __f, __v); |
| 42 | + #else |
| 43 | + __fh_size_t __b = __fh_bos(__s, 0); |
| 44 | +@@ -200,7 +200,7 @@ __diagnose_as_builtin(__builtin_vfprintf |
| 45 | + #endif |
| 46 | + _FORTIFY_FN(vfprintf) int vfprintf(FILE * __s, const char *__f, __builtin_va_list __v) |
| 47 | + { |
| 48 | +-#if __has_builtin(__builtin___vfprintf_chk) && FORTIFY_USE_NATIVE_CHK |
| 49 | ++#if __has_builtin(__builtin___vfprintf_chk) && defined(FORTIFY_USE_NATIVE_CHK) |
| 50 | + return __builtin___vfprintf_chk(__s, _FORTIFY_SOURCE, __f, __v); |
| 51 | + #else |
| 52 | + return __orig_vfprintf(__s, __f, __v); |
| 53 | +@@ -214,7 +214,7 @@ __diagnose_as_builtin(__builtin_vprintf, |
| 54 | + #endif |
| 55 | + _FORTIFY_FN(vprintf) int vprintf(const char *__f, __builtin_va_list __v) |
| 56 | + { |
| 57 | +-#if __has_builtin(__builtin___vprintf_chk) && FORTIFY_USE_NATIVE_CHK |
| 58 | ++#if __has_builtin(__builtin___vprintf_chk) && defined(FORTIFY_USE_NATIVE_CHK) |
| 59 | + return __builtin___vprintf_chk(_FORTIFY_SOURCE, __f, __v); |
| 60 | + #else |
| 61 | + return __orig_vprintf(__f, __v); |
| 62 | +@@ -228,7 +228,7 @@ __diagnose_as_builtin(__builtin_vasprint |
| 63 | + #endif |
| 64 | + _FORTIFY_FN(vasprintf) int vasprintf(char **strp, const char *fmt, __builtin_va_list ap) |
| 65 | + { |
| 66 | +-#if __has_builtin(__builtin___vasprintf_chk) && FORTIFY_USE_NATIVE_CHK |
| 67 | ++#if __has_builtin(__builtin___vasprintf_chk) && defined(FORTIFY_USE_NATIVE_CHK) |
| 68 | + return __builtin___vasprintf_chk(_FORTIFY_SOURCE, strp, fmt, ap); |
| 69 | + #else |
| 70 | + int ret = __orig_vasprintf(strp, fmt, ap); |
| 71 | +@@ -275,7 +275,7 @@ __fh_format(printf, 3, 4) |
| 72 | + _FORTIFY_FN(snprintf) int snprintf(char *__s, size_t __n, |
| 73 | + const char *__f, ...) |
| 74 | + { |
| 75 | +-#if __has_builtin(__builtin___snprintf_chk) && FORTIFY_USE_NATIVE_CHK |
| 76 | ++#if __has_builtin(__builtin___snprintf_chk) && defined(FORTIFY_USE_NATIVE_CHK) |
| 77 | + return __builtin___snprintf_chk(__s, __n, _FORTIFY_SOURCE, __fh_bos(__s, 0), __f, __builtin_va_arg_pack()); |
| 78 | + #else |
| 79 | + __fh_size_t __b = __fh_bos(__s, 0); |
| 80 | +@@ -291,7 +291,7 @@ __fh_format(printf, 2, 3) |
| 81 | + __fh_access(read_only, 2) |
| 82 | + _FORTIFY_FN(sprintf) int sprintf(char *__s, const char *__f, ...) |
| 83 | + { |
| 84 | +-#if __has_builtin(__builtin___sprintf_chk) && FORTIFY_USE_NATIVE_CHK |
| 85 | ++#if __has_builtin(__builtin___sprintf_chk) && defined(FORTIFY_USE_NATIVE_CHK) |
| 86 | + return __builtin___sprintf_chk(__s, _FORTIFY_SOURCE, __fh_bos(__s, 0), __f, __builtin_va_arg_pack()); |
| 87 | + #else |
| 88 | + __fh_size_t __b = __fh_bos(__s, 0); |
| 89 | +@@ -312,7 +312,7 @@ __fh_format(printf, 1, 2) |
| 90 | + __fh_access(read_only, 1) |
| 91 | + _FORTIFY_FN(printf) int printf(const char *__f, ...) |
| 92 | + { |
| 93 | +-#if __has_builtin(__builtin___printf_chk) && FORTIFY_USE_NATIVE_CHK |
| 94 | ++#if __has_builtin(__builtin___printf_chk) && defined(FORTIFY_USE_NATIVE_CHK) |
| 95 | + return __builtin___printf_chk(_FORTIFY_SOURCE, __f, __builtin_va_arg_pack()); |
| 96 | + #else |
| 97 | + return __orig_printf(__f, __builtin_va_arg_pack()); |
| 98 | +@@ -326,7 +326,7 @@ __diagnose_as_builtin(__builtin_fprintf, |
| 99 | + #endif |
| 100 | + _FORTIFY_FN(fprintf) int fprintf(FILE *__s, const char *__f, ...) |
| 101 | + { |
| 102 | +-#if __has_builtin(__builtin___fprintf_chk) && FORTIFY_USE_NATIVE_CHK |
| 103 | ++#if __has_builtin(__builtin___fprintf_chk) && defined(FORTIFY_USE_NATIVE_CHK) |
| 104 | + return __builtin___fprintf_chk(_FORTIFY_SOURCE, __s, __f, __builtin_va_arg_pack()); |
| 105 | + #else |
| 106 | + return __orig_fprintf(__s, __f, __builtin_va_arg_pack()); |
| 107 | +@@ -343,7 +343,7 @@ __diagnose_as_builtin(__builtin_asprintf |
| 108 | + #endif |
| 109 | + _FORTIFY_FN(asprintf) int asprintf(char **strp, const char *fmt, ...) |
| 110 | + { |
| 111 | +-#if __has_builtin(__builtin___asprintf_chk) && FORTIFY_USE_NATIVE_CHK |
| 112 | ++#if __has_builtin(__builtin___asprintf_chk) && defined(FORTIFY_USE_NATIVE_CHK) |
| 113 | + return __builtin___asprintf_chk(_FORTIFY_SOURCE, strp, fmt, __builtin_va_arg_pack()); |
| 114 | + #else |
| 115 | + int ret = __orig_asprintf(strp, fmt, __builtin_va_arg_pack()); |
| 116 | +--- a/include/string.h |
| 117 | ++++ b/include/string.h |
| 118 | +@@ -48,7 +48,7 @@ _FORTIFY_FN(memcpy) void *memcpy(void * |
| 119 | + const void * _FORTIFY_POS0 __os, size_t __n) |
| 120 | + __error_if((__fh_bos(__od, 0) < __n), "'memcpy' called with `n` bigger than the size of `d`.") |
| 121 | + { |
| 122 | +-#if __has_builtin(__builtin___memcpy_chk) && FORTIFY_USE_NATIVE_CHK |
| 123 | ++#if __has_builtin(__builtin___memcpy_chk) && defined(FORTIFY_USE_NATIVE_CHK) |
| 124 | + return __builtin___memcpy_chk(__od, __os, __n, __fh_bos(__od, 0)); |
| 125 | + #else |
| 126 | + #if defined FORTIFY_PEDANTIC_CHECKS |
| 127 | +@@ -75,7 +75,7 @@ __diagnose_as_builtin(__builtin_memmove, |
| 128 | + _FORTIFY_FN(memmove) void *memmove(void * _FORTIFY_POS0 __d, |
| 129 | + const void * _FORTIFY_POS0 __s, size_t __n) |
| 130 | + { |
| 131 | +-#if __has_builtin(__builtin___memmove_chk) && FORTIFY_USE_NATIVE_CHK |
| 132 | ++#if __has_builtin(__builtin___memmove_chk) && defined(FORTIFY_USE_NATIVE_CHK) |
| 133 | + return __builtin___memmove_chk(__d, __s, __n, __fh_bos(__d, 0)); |
| 134 | + #else |
| 135 | + #if defined FORTIFY_PEDANTIC_CHECKS |
| 136 | +@@ -99,7 +99,7 @@ __diagnose_as_builtin(__builtin_memset, |
| 137 | + _FORTIFY_FN(memset) void *memset(void * _FORTIFY_POS0 __d, int __c, size_t __n) |
| 138 | + __warning_if(__c != 0 && __n == 0, "'memset' will set `0` bytes; did you invert the arguments?") |
| 139 | + { |
| 140 | +-#if __has_builtin(__builtin___memset_chk) && FORTIFY_USE_NATIVE_CHK |
| 141 | ++#if __has_builtin(__builtin___memset_chk) && defined(FORTIFY_USE_NATIVE_CHK) |
| 142 | + return __builtin___memset_chk(__d, __c, __n, __fh_bos(__d, 0)); |
| 143 | + #else |
| 144 | + #if defined FORTIFY_PEDANTIC_CHECKS |
| 145 | +@@ -121,7 +121,7 @@ __diagnose_as_builtin(__builtin_memchr, |
| 146 | + #endif |
| 147 | + _FORTIFY_FN(memchr) void *memchr(const void * _FORTIFY_POS0 __d, int __c, size_t __n) |
| 148 | + { |
| 149 | +-#if __has_builtin(__builtin___memchr_chk) && FORTIFY_USE_NATIVE_CHK |
| 150 | ++#if __has_builtin(__builtin___memchr_chk) && defined(FORTIFY_USE_NATIVE_CHK) |
| 151 | + return __builtin___memchr_chk(__d, __c, __n, __fh_bos(__d, 0)); |
| 152 | + #else |
| 153 | + #if defined FORTIFY_PEDANTIC_CHECKS |
| 154 | +@@ -142,7 +142,7 @@ _FORTIFY_FN(memchr) void *memchr(const v |
| 155 | + __fh_access(read_only, 1, 2) |
| 156 | + _FORTIFY_FN(strchr) char *strchr(const char * _FORTIFY_POS0 __s, int __c) |
| 157 | + { |
| 158 | +-#if __has_builtin(__builtin___strchr_chk) && FORTIFY_USE_NATIVE_CHK |
| 159 | ++#if __has_builtin(__builtin___strchr_chk) && defined(FORTIFY_USE_NATIVE_CHK) |
| 160 | + return __builtin___strchr_chk(__s, __c, __fh_bos(__s, 0)); |
| 161 | + #else |
| 162 | + __fh_size_t __b = __fh_bos(__s, 0); |
| 163 | +@@ -157,7 +157,7 @@ _FORTIFY_FN(strchr) char *strchr(const c |
| 164 | + __fh_access(read_only, 1, 2) |
| 165 | + _FORTIFY_FN(strrchr) char *strrchr(const char * _FORTIFY_POS0 __s, int __c) |
| 166 | + { |
| 167 | +-#if __has_builtin(__builtin___strrchr_chk) && FORTIFY_USE_NATIVE_CHK |
| 168 | ++#if __has_builtin(__builtin___strrchr_chk) && defined(FORTIFY_USE_NATIVE_CHK) |
| 169 | + return __builtin___strrchr_chk(__s, __c, __fh_bos(__s, 0)); |
| 170 | + #else |
| 171 | + __fh_size_t __b = __fh_bos(__s, 0); |
| 172 | +@@ -181,7 +181,7 @@ __diagnose_as_builtin(__builtin_stpcpy, |
| 173 | + #endif |
| 174 | + _FORTIFY_FN(stpcpy) char *stpcpy(char * _FORTIFY_POS0 __d, const char *__s) |
| 175 | + { |
| 176 | +-#if __has_builtin(__builtin___stpcpy_chk) && FORTIFY_USE_NATIVE_CHK |
| 177 | ++#if __has_builtin(__builtin___stpcpy_chk) && defined(FORTIFY_USE_NATIVE_CHK) |
| 178 | + return __builtin___stpcpy_chk(__d, __s, __fh_bos(__d, 0)); |
| 179 | + #else |
| 180 | + __fh_size_t __n = strlen(__s) + 1; |
| 181 | +@@ -205,7 +205,7 @@ __diagnose_as_builtin(__builtin_stpncpy, |
| 182 | + _FORTIFY_FN(stpncpy) char *stpncpy(char * _FORTIFY_POS0 __d, const char *__s, |
| 183 | + size_t __n) |
| 184 | + { |
| 185 | +-#if __has_builtin(__builtin___stpncpy_chk) && FORTIFY_USE_NATIVE_CHK |
| 186 | ++#if __has_builtin(__builtin___stpncpy_chk) && defined(FORTIFY_USE_NATIVE_CHK) |
| 187 | + return __builtin___stpncpy_chk(__d, __s, __n, __fh_bos(__d, 0)); |
| 188 | + #else |
| 189 | + // If the length strlen(src) is smaller than n, the remaining |
| 190 | +@@ -227,7 +227,7 @@ __diagnose_as_builtin(__builtin_strcat, |
| 191 | + #endif |
| 192 | + _FORTIFY_FN(strcat) char *strcat(char * _FORTIFY_POS0 __d, const char *__s) |
| 193 | + { |
| 194 | +-#if __has_builtin(__builtin___strcat_chk) && FORTIFY_USE_NATIVE_CHK |
| 195 | ++#if __has_builtin(__builtin___strcat_chk) && defined(FORTIFY_USE_NATIVE_CHK) |
| 196 | + return __builtin___strcat_chk(__d, __s, __fh_bos(__d, 0)); |
| 197 | + #else |
| 198 | + __fh_size_t __b = __fh_bos(__d, 0); |
| 199 | +@@ -245,7 +245,7 @@ __diagnose_as_builtin(__builtin_strcpy, |
| 200 | + #endif |
| 201 | + _FORTIFY_FN(strcpy) char *strcpy(char * _FORTIFY_POS0 __d, const char *__s) |
| 202 | + { |
| 203 | +-#if __has_builtin(__builtin___strcpy_chk) && FORTIFY_USE_NATIVE_CHK |
| 204 | ++#if __has_builtin(__builtin___strcpy_chk) && defined(FORTIFY_USE_NATIVE_CHK) |
| 205 | + return __builtin___strcpy_chk(__d, __s, __fh_bos(__d, 0)); |
| 206 | + #else |
| 207 | + __fh_size_t __n = strlen(__s) + 1; |
| 208 | +@@ -266,7 +266,7 @@ __diagnose_as_builtin(__builtin_strlen, |
| 209 | + #endif |
| 210 | + _FORTIFY_FN(strlen) size_t strlen(const char * _FORTIFY_POS0 __s) |
| 211 | + { |
| 212 | +-#if __has_builtin(__builtin___strlen_chk) && FORTIFY_USE_NATIVE_CHK |
| 213 | ++#if __has_builtin(__builtin___strlen_chk) && defined(FORTIFY_USE_NATIVE_CHK) |
| 214 | + return __builtin___strlen_chk(__s, __fh_bos(__s, 0)); |
| 215 | + #else |
| 216 | + __fh_size_t ret = __orig_strlen(__s); |
| 217 | +@@ -284,7 +284,7 @@ __diagnose_as_builtin(__builtin_strncat, |
| 218 | + _FORTIFY_FN(strncat) char *strncat(char * _FORTIFY_POS0 __d, const char *__s, |
| 219 | + size_t __n) |
| 220 | + { |
| 221 | +-#if __has_builtin(__builtin___strncat_chk) && FORTIFY_USE_NATIVE_CHK |
| 222 | ++#if __has_builtin(__builtin___strncat_chk) && defined(FORTIFY_USE_NATIVE_CHK) |
| 223 | + return __builtin___strncat_chk(__d, __s, __n, __fh_bos(__d, 0)); |
| 224 | + #else |
| 225 | + #if 0 // strlen(__s) isn't guaranteed to be valid. |
| 226 | +@@ -311,7 +311,7 @@ __diagnose_as_builtin(__builtin_strncpy, |
| 227 | + _FORTIFY_FN(strncpy) char *strncpy(char * _FORTIFY_POS0 __d, |
| 228 | + const char *__s, size_t __n) |
| 229 | + { |
| 230 | +-#if __has_builtin(__builtin___strncpy_chk) && FORTIFY_USE_NATIVE_CHK |
| 231 | ++#if __has_builtin(__builtin___strncpy_chk) && defined(FORTIFY_USE_NATIVE_CHK) |
| 232 | + return __builtin___strncpy_chk(__d, __s, __n, __fh_bos(__d, 0)); |
| 233 | + #else |
| 234 | + // If the length of src is less than n, strncpy() writes additional |
| 235 | +@@ -334,7 +334,7 @@ __diagnose_as_builtin(__builtin_mempcpy, |
| 236 | + _FORTIFY_FN(mempcpy) void *mempcpy(void * _FORTIFY_POS0 __d, |
| 237 | + const void * _FORTIFY_POS0 __s, size_t __n) |
| 238 | + { |
| 239 | +-#if __has_builtin(__builtin___mempcpy_chk) && FORTIFY_USE_NATIVE_CHK |
| 240 | ++#if __has_builtin(__builtin___mempcpy_chk) && defined(FORTIFY_USE_NATIVE_CHK) |
| 241 | + return __builtin___mempcpy_chk(__d, __s, __n, __fh_bos(__d, 0)); |
| 242 | + #else |
| 243 | + if (!__d || !__s) |
| 244 | +@@ -361,7 +361,7 @@ __diagnose_as_builtin(__builtin_strlcat, |
| 245 | + _FORTIFY_FN(strlcat) size_t strlcat(char * _FORTIFY_POS0 __d, |
| 246 | + const char *__s, size_t __n) |
| 247 | + { |
| 248 | +-#if __has_builtin(__builtin___strlcat_chk) && FORTIFY_USE_NATIVE_CHK |
| 249 | ++#if __has_builtin(__builtin___strlcat_chk) && defined(FORTIFY_USE_NATIVE_CHK) |
| 250 | + return __builtin___strlcat_chk(__d, __s, __n, __fh_bos(__d, 0)); |
| 251 | + #else |
| 252 | + __fh_size_t __b = __fh_bos(__d, 0); |
| 253 | +@@ -380,7 +380,7 @@ __diagnose_as_builtin(__builtin_strlcpy, |
| 254 | + _FORTIFY_FN(strlcpy) size_t strlcpy(char * _FORTIFY_POS0 __d, |
| 255 | + const char *__s, size_t __n) |
| 256 | + { |
| 257 | +-#if __has_builtin(__builtin___strlcpy_chk) && FORTIFY_USE_NATIVE_CHK |
| 258 | ++#if __has_builtin(__builtin___strlcpy_chk) && defined(FORTIFY_USE_NATIVE_CHK) |
| 259 | + return __builtin___strlcpy_chk(__d, __s, __n, __fh_bos(__d, 0)); |
| 260 | + #else |
| 261 | + __fh_size_t __b = __fh_bos(__d, 0); |
0 commit comments