Skip to content

Commit 8c395d2

Browse files
committed
safeclib: init at 3.9.1
1 parent 60b4bdf commit 8c395d2

File tree

6 files changed

+613
-0
lines changed

6 files changed

+613
-0
lines changed

releases.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3620,6 +3620,14 @@
36203620
"4.1.0-1"
36213621
]
36223622
},
3623+
"safeclib": {
3624+
"dependency_names": [
3625+
"libsafec"
3626+
],
3627+
"versions": [
3628+
"3.9.1-1"
3629+
]
3630+
},
36233631
"sassc": {
36243632
"program_names": [
36253633
"sassc"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
configure_file(
2+
input: 'safe_config.h.in',
3+
output: 'safe_config.h',
4+
configuration: conf,
5+
)
6+
configure_file(
7+
input: 'safe_lib_errno.h.in',
8+
output: 'safe_lib_errno.h',
9+
configuration: conf,
10+
)
11+
configure_file(
12+
input: 'safe_types.h.in',
13+
output: 'safe_types.h',
14+
configuration: conf,
15+
)
16+
17+
inc = include_directories('.')
Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
project(
2+
'safeclib',
3+
'c',
4+
version: '3.9.1',
5+
license: 'MIT',
6+
meson_version: '>=1.3.0',
7+
)
8+
9+
cc = meson.get_compiler('c')
10+
11+
conf = configuration_data()
12+
13+
conf.set(
14+
'INSERT_BOOL_SUPPORT',
15+
cc.check_header('stdbool.h') ? '#include <stdbool.h>' : '',
16+
)
17+
conf.set(
18+
'INSERT_INTTYPES_H',
19+
cc.check_header('inttypes.h') ? '#include <inttypes.h>' : '',
20+
)
21+
conf.set(
22+
'INSERT_STDINT_H',
23+
cc.check_header('stdint.h') ? '#include <stdint.h>' : '',
24+
)
25+
conf.set(
26+
'INSERT_SYS_TYPES_H',
27+
cc.check_header('sys/types.h') ? '#include <sys/types.h>' : '',
28+
)
29+
conf.set('INSERT_ERRNO_H', cc.check_header('errno.h') ? '#include <errno.h>' : '')
30+
31+
funcs = ('vswprintf vswscanf mbsrtowcs ' +
32+
'__bnd_chk_ptr_bounds __bnd_set_ptr_bounds __bnd_null_ptr_bounds ' +
33+
'__memcpy_chk __memmove_chk __memset_chk ' +
34+
'__strcpy_chk __strncpy_chk __strcat_chk __strncat_chk ' +
35+
'__printf_chk __sprintf_chk __snprintf_chk ' +
36+
'__vfprintf_chk __vfwprintf_chk __vsprintf_chk __vsnprintf_chk ' +
37+
'__vsscanf_chk ' +
38+
'memset strcmp strcasecmp strcasestr strcspn strpbrk strspn ' +
39+
'strnstr strnlen strrchr memrchr strstr bcmp secure_getenv timingsafe_memcmp ' +
40+
'timingsafe_bcmp explicit_bzero explicit_memset ' +
41+
'asctime_r ctime_r gmtime_r localtime_r memccpy stpcpy stpncpy strerror ' +
42+
'fileno ftruncate isinfl ' +
43+
'wmemchr wmemcmp wcscmp wcsstr ' +
44+
'vswprintf vsnwprintf vswscanf mbsrtowcs mbstowcs iswdigit iswspace ' +
45+
'towlower towupper towctrans ' +
46+
'_memcpy_s_chk _memmove_s_chk _memset_s_chk _memcmp_s_chk ' +
47+
'_strcpy_s_chk _strncpy_s_chk _strcat_s_chk _strncat_s_chk _strnlen_s_chk ' +
48+
'_printf_s_chk _sprintf_s_chk _snprintf_s_chk ' +
49+
'_vfprintf_s_chk _vsprintf_s_chk _vsnprintf_s_chk ' +
50+
'memset_s memcpy_s memmove_s memzero_s memchr_s memrchr_s memccpy_s ' +
51+
'sprintf_s strcat_s strcpy_s strncat_s strncpy_s ' +
52+
'strnlen_s strtok_s strerror_s vsprintf_s tmpnam_s snprintf_s vsnprintf_s ' +
53+
'strspn_s strset_s strchr_s strrchr_s strstr_s strzero_s strnset_s ' +
54+
'stpcpy_s stpncpy_s ' +
55+
'sscanf_s fscanf_s scanf_s vfscanf_s ' +
56+
'vsscanf_s vscanf_s printf_s fprintf_s tmpfile_s vfprintf_s vprintf_s ' +
57+
'fopen_s freopen_s gets_s bsearch_s qsort_s gmtime_s localtime_s ' +
58+
'asctime_s ctime_s getenv_s feenableexcept ' +
59+
'mbsrtowcs_s mbstowcs_s wcsrtombs_s wcstombs_s ' +
60+
'wcrtomb_s wctomb_s wcsnlen_s wcscpy_s wcsncpy_s wcscat_s wcsncat_s ' +
61+
'wmemcpy_s wmemmove_s wcstok_s vswprintf_s swprintf_s vfwprintf_s ' +
62+
'vwprintf_s wprintf_s snwprintf_s fwprintf_s swscanf_s vswscanf_s wscanf_s ' +
63+
'vfwscanf_s fwscanf_s vwscanf_s vsnwprintf_s wcsstr_s wmemcmp_s ' +
64+
'wcscmp_s wcsncmp_s wcsicmp_s wcsset_s wcsnset_s wcscoll_s wcslwr_s ' +
65+
'wcsupr_s towfc_s wcsfc_s ' +
66+
'_swprintf_s_chk _vfwprintf_s_chk').split(' ')
67+
foreach f : funcs
68+
conf.set('HAVE_@0@'.format(f.underscorify().to_upper()), cc.has_function(f))
69+
endforeach
70+
71+
headers = [
72+
'sys/time.h',
73+
'stdlib.h',
74+
'memory.h',
75+
'ctype.h',
76+
'malloc.h',
77+
'string.h',
78+
'limits.h',
79+
'stddef.h',
80+
'unistd.h',
81+
'float.h',
82+
'math.h',
83+
'sys/types.h',
84+
'inttypes.h',
85+
'stdint.h',
86+
'errno.h',
87+
'wchar.h',
88+
'langinfo.h',
89+
'valgrind/valgrind.h',
90+
'fenv.h',
91+
'intrin.h',
92+
'xmmintrin.h',
93+
'emmintrin.h',
94+
'x86intrin.h',
95+
'arm_neon.h',
96+
'arm_acle.h',
97+
'mmintrin.h',
98+
'altivec.h',
99+
'spe.h',
100+
'mbarrier.h',
101+
]
102+
foreach h : headers
103+
conf.set(
104+
'HAVE_@0@'.format(h.underscorify().to_upper()),
105+
cc.check_header(h)
106+
)
107+
endforeach
108+
109+
sizeofs = ['size_t', 'wchar_t', 'time_t']
110+
foreach s : sizeofs
111+
conf.set('SIZEOF_@0@'.format(s.underscorify().to_upper()), cc.sizeof(s))
112+
endforeach
113+
114+
conf.set(
115+
'HAVE_TM_GMTOFF',
116+
cc.has_member(
117+
'struct tm',
118+
'tm_gmtoff',
119+
prefix: '#include <time.h>',
120+
),
121+
)
122+
conf.set('HAVE_FLOAT128', cc.compiles('int main(void) { __float128 x = 1.0Q; }'))
123+
conf.set(
124+
'HAVE_TOWUPPER_OK',
125+
cc.run(
126+
'''
127+
#include <wctype.h>
128+
int main(void) {
129+
return (towupper(0x1C80) == 0x412
130+
&& towupper(0xB5) == 0x3BC
131+
&& towupper(0x432) == 0x1C80)
132+
? 0 : 1;
133+
}
134+
''',
135+
).returncode() == 0,
136+
)
137+
conf.set(
138+
'HAVE_STRNSTR_OK',
139+
cc.run(
140+
'''
141+
#include <string.h>
142+
int main(void) {
143+
return strnstr("%s %n", "%n", 6) ? 0 : 1;
144+
}
145+
''',
146+
).returncode() == 0 ? '1' : false,
147+
)
148+
149+
conf.set(
150+
'PRINTF_DISABLE_SUPPORT_FLOAT',
151+
get_option('float').allowed() ? false : 1,
152+
)
153+
conf.set(
154+
'PRINTF_DISABLE_SUPPORT_EXPONENTIAL',
155+
get_option('float-exp').allowed() ? false : 1,
156+
)
157+
conf.set(
158+
'PRINTF_DISABLE_SUPPORT_LONG_LONG',
159+
get_option('long-long').allowed() ? false : 1,
160+
)
161+
conf.set(
162+
'PRINTF_DISABLE_SUPPORT_LONG_DOUBLE',
163+
get_option('long-double').allowed() ? false : 1,
164+
)
165+
conf.set(
166+
'PRINTF_DISABLE_SUPPORT_PTRDIFF_T',
167+
get_option('printf-ptrdiff').allowed() ? false : 1,
168+
)
169+
170+
conf.set(
171+
'INSERT_EXTS',
172+
get_option('extensions').allowed() ? '#undef SAFECLIB_DISABLE_EXTENSIONS' : '#define SAFECLIB_DISABLE_EXTENSIONS 1',
173+
)
174+
conf.set(
175+
'INSERT_NULLSLACK',
176+
get_option('nullslack').allowed() ? '#define SAFECLIB_STR_NULL_SLACK 1' : '#undef SAFECLIB_STR_NULL_SLACK',
177+
)
178+
conf.set(
179+
'INSERT_CONSTRAINT_HANDLER',
180+
get_option('constraint-handler').allowed() ? '#undef SAFECLIB_DISABLE_CONSTRAINT_HANDLER' : '#define SAFECLIB_DISABLE_CONSTRAINT_HANDLER 1',
181+
)
182+
conf.set(
183+
'INSERT_UNSAFE',
184+
get_option('unsafe').allowed() ? '#define SAFECLIB_ENABLE_UNSAFE 1' : '#undef SAFECLIB_ENABLE_UNSAFE',
185+
)
186+
haveBuiltinObjectSize = cc.has_function('__builtin_object_size')
187+
conf.set('HAVE___BUILTIN_OBJECT_SIZE', haveBuiltinObjectSize ? '1' : false)
188+
conf.set(
189+
'INSERT_OBJECT_SIZE',
190+
haveBuiltinObjectSize ? '#define HAVE___BUILTIN_OBJECT_SIZE 1' : '',
191+
)
192+
conf.set(
193+
'INSERT_WARN_DMAX',
194+
(get_option('warn-dmax').allowed() or get_option('error-dmax').allowed()) and haveBuiltinObjectSize ? '#define HAVE_WARN_DMAX 1' : '',
195+
)
196+
conf.set(
197+
'INSERT_ERROR_DMAX',
198+
get_option('error-dmax').allowed() and haveBuiltinObjectSize ? '#define HAVE_ERROR_DMAX 1' : '',
199+
)
200+
conf.set(
201+
'INSERT_DEFAULT_HANDLER',
202+
get_option('default-handler') == 'no' ? '#undef SAFECLIB_DEFAULT_HANDLER' : '#define SAFECLIB_DEFAULT_HANDLER @0@_handler_s'.format(
203+
get_option('default-handler'),
204+
),
205+
)
206+
conf.set(
207+
'INSERT_CONSTANT_P',
208+
cc.has_function('__builtin_constant_p') ? '#define HAVE___BUILTIN_CONSTANT_P 1' : '#undef HAVE___BUILTIN_CONSTANT_P',
209+
)
210+
conf.set('INSERT_DISABLE_DLLIMPORT', '#undef DISABLE_DLLIMPORT')
211+
conf.set(
212+
'INSERT_DISABLE_WCHAR',
213+
get_option('wchar').allowed() ? '#undef SAFECLIB_DISABLE_WCHAR' : '#define SAFECLIB_DISABLE_WCHAR 1',
214+
)
215+
conf.set('INSERT_SAFECLIB_HAVE_C99', '#define SAFECLIB_HAVE_C99 1')
216+
conf.set('RSIZE_MAX_MEM', get_option('memmax'))
217+
conf.set('RSIZE_MAX_STR', get_option('strmax'))
218+
conf.set(
219+
'FALLBACK_ERRNO_T',
220+
cc.has_type(
221+
'errno_t',
222+
prefix: '#include <errno.h>',
223+
) ? '' : 'typedef int errno_t;',
224+
)
225+
conf.set('HAVE_ATTRIBUTE_FORMAT_WPRINTF', '0')
226+
conf.set('HAVE_ATTRIBUTE_FORMAT_WSCANF', '0')
227+
conf.set('STDC_HEADERS', true)
228+
conf.set('configure_input', '')
229+
230+
subdir('include')
231+
subdir('src')
232+
233+
libsafec_dep = declare_dependency(
234+
include_directories: inc,
235+
link_with: libsafec,
236+
)
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
option(
2+
'extensions',
3+
type: 'feature',
4+
description: 'This library contains additional functions not defined in the C11 specification. Disable to omit these.',
5+
value: 'enabled',
6+
)
7+
8+
option(
9+
'float',
10+
type: 'feature',
11+
description: 'Enable float support in the printf functions.',
12+
value: 'enabled',
13+
)
14+
15+
option(
16+
'float-exp',
17+
type: 'feature',
18+
description: 'Enable exponential floating point notation (%e/%g) in the printf functions.',
19+
value: 'enabled',
20+
)
21+
22+
option(
23+
'long-long',
24+
type: 'feature',
25+
description: 'Enable exponential floating point notation (%e/%g) in the printf functions.',
26+
value: 'enabled',
27+
)
28+
29+
option(
30+
'long-double',
31+
type: 'feature',
32+
description: 'Enable exponential floating point notation (%e/%g) in the printf functions.',
33+
value: 'enabled',
34+
)
35+
36+
option(
37+
'printf-ptrdiff',
38+
type: 'feature',
39+
description: 'Enable ptrdiff_t type (%t) in the printf functions.',
40+
value: 'enabled',
41+
)
42+
43+
option(
44+
'memmax',
45+
type: 'integer',
46+
description: 'specify the largest object size allowed for the mem* functions',
47+
value: 268435456, # 256MiB
48+
)
49+
50+
option(
51+
'strmax',
52+
type: 'integer',
53+
description: 'specify the largest object size allowed for the str* functions',
54+
value: 4096, # 4KiB
55+
)
56+
57+
option(
58+
'nullslack',
59+
type: 'feature',
60+
description: 'Null out the remaining part of a string if it is not completely used',
61+
value: 'enabled',
62+
)
63+
64+
option(
65+
'constraint-handler',
66+
type: 'feature',
67+
description: 'Enable C11 invoke_safe_{str,mem}_constraint_handler for performance, smaller size and less flexibility.',
68+
value: 'enabled',
69+
)
70+
71+
option(
72+
'unsafe',
73+
type: 'feature',
74+
description: 'Include unsafe std C11 functions: tmpnam_s',
75+
value: 'disabled',
76+
)
77+
78+
option(
79+
'warn-dmax',
80+
type: 'feature',
81+
description: 'Enable dmax checks against __builtin_object_size(dest).',
82+
value: 'disabled',
83+
)
84+
85+
option(
86+
'error-dmax',
87+
type: 'feature',
88+
description: 'Make --enable-warn-dmax fatal.',
89+
value: 'disabled',
90+
)
91+
92+
option(
93+
'default-handler',
94+
type: 'combo',
95+
choices: ['ignore', 'abort', 'no'],
96+
description: 'enforce compile-time default-handler',
97+
value: 'no',
98+
)
99+
100+
option(
101+
'wchar',
102+
type: 'feature',
103+
description: 'Enable multibyte and wchar support.',
104+
value: 'enabled',
105+
)

0 commit comments

Comments
 (0)