From 3953432857c9949fd48b568ab2632fde56a3831a Mon Sep 17 00:00:00 2001 From: Piper McCorkle Date: Tue, 29 Jul 2025 17:39:51 -0500 Subject: [PATCH] safeclib: init at 3.9.1 --- releases.json | 8 + .../packagefiles/safeclib/include/meson.build | 17 ++ subprojects/packagefiles/safeclib/meson.build | 236 +++++++++++++++++ .../packagefiles/safeclib/meson.options | 105 ++++++++ .../packagefiles/safeclib/src/meson.build | 238 ++++++++++++++++++ subprojects/safeclib.wrap | 9 + 6 files changed, 613 insertions(+) create mode 100644 subprojects/packagefiles/safeclib/include/meson.build create mode 100644 subprojects/packagefiles/safeclib/meson.build create mode 100644 subprojects/packagefiles/safeclib/meson.options create mode 100644 subprojects/packagefiles/safeclib/src/meson.build create mode 100644 subprojects/safeclib.wrap diff --git a/releases.json b/releases.json index c20bcc8a4..540b283b4 100644 --- a/releases.json +++ b/releases.json @@ -3620,6 +3620,14 @@ "4.1.0-1" ] }, + "safeclib": { + "dependency_names": [ + "libsafec" + ], + "versions": [ + "3.9.1-1" + ] + }, "sassc": { "program_names": [ "sassc" diff --git a/subprojects/packagefiles/safeclib/include/meson.build b/subprojects/packagefiles/safeclib/include/meson.build new file mode 100644 index 000000000..66fce9c30 --- /dev/null +++ b/subprojects/packagefiles/safeclib/include/meson.build @@ -0,0 +1,17 @@ +configure_file( + input: 'safe_config.h.in', + output: 'safe_config.h', + configuration: conf, +) +configure_file( + input: 'safe_lib_errno.h.in', + output: 'safe_lib_errno.h', + configuration: conf, +) +configure_file( + input: 'safe_types.h.in', + output: 'safe_types.h', + configuration: conf, +) + +inc = include_directories('.') diff --git a/subprojects/packagefiles/safeclib/meson.build b/subprojects/packagefiles/safeclib/meson.build new file mode 100644 index 000000000..ca7bd9ce3 --- /dev/null +++ b/subprojects/packagefiles/safeclib/meson.build @@ -0,0 +1,236 @@ +project( + 'safeclib', + 'c', + version: '3.9.1', + license: 'MIT', + meson_version: '>=1.3.0', +) + +cc = meson.get_compiler('c') + +conf = configuration_data() + +conf.set( + 'INSERT_BOOL_SUPPORT', + cc.check_header('stdbool.h') ? '#include ' : '', +) +conf.set( + 'INSERT_INTTYPES_H', + cc.check_header('inttypes.h') ? '#include ' : '', +) +conf.set( + 'INSERT_STDINT_H', + cc.check_header('stdint.h') ? '#include ' : '', +) +conf.set( + 'INSERT_SYS_TYPES_H', + cc.check_header('sys/types.h') ? '#include ' : '', +) +conf.set( + 'INSERT_ERRNO_H', + cc.check_header('errno.h') ? '#include ' : '', +) + +funcs = ('vswprintf vswscanf mbsrtowcs ' + +'__bnd_chk_ptr_bounds __bnd_set_ptr_bounds __bnd_null_ptr_bounds ' + +'__memcpy_chk __memmove_chk __memset_chk ' + +'__strcpy_chk __strncpy_chk __strcat_chk __strncat_chk ' + +'__printf_chk __sprintf_chk __snprintf_chk ' + +'__vfprintf_chk __vfwprintf_chk __vsprintf_chk __vsnprintf_chk ' + +'__vsscanf_chk ' + +'memset strcmp strcasecmp strcasestr strcspn strpbrk strspn ' + +'strnstr strnlen strrchr memrchr strstr bcmp secure_getenv timingsafe_memcmp ' + +'timingsafe_bcmp explicit_bzero explicit_memset ' + +'asctime_r ctime_r gmtime_r localtime_r memccpy stpcpy stpncpy strerror ' + +'fileno ftruncate isinfl ' + +'wmemchr wmemcmp wcscmp wcsstr ' + +'vswprintf vsnwprintf vswscanf mbsrtowcs mbstowcs iswdigit iswspace ' + +'towlower towupper towctrans ' + +'_memcpy_s_chk _memmove_s_chk _memset_s_chk _memcmp_s_chk ' + +'_strcpy_s_chk _strncpy_s_chk _strcat_s_chk _strncat_s_chk _strnlen_s_chk ' + +'_printf_s_chk _sprintf_s_chk _snprintf_s_chk ' + +'_vfprintf_s_chk _vsprintf_s_chk _vsnprintf_s_chk ' + +'memset_s memcpy_s memmove_s memzero_s memchr_s memrchr_s memccpy_s ' + +'sprintf_s strcat_s strcpy_s strncat_s strncpy_s ' + +'strnlen_s strtok_s strerror_s vsprintf_s tmpnam_s snprintf_s vsnprintf_s ' + +'strspn_s strset_s strchr_s strrchr_s strstr_s strzero_s strnset_s ' + +'stpcpy_s stpncpy_s ' + +'sscanf_s fscanf_s scanf_s vfscanf_s ' + +'vsscanf_s vscanf_s printf_s fprintf_s tmpfile_s vfprintf_s vprintf_s ' + +'fopen_s freopen_s gets_s bsearch_s qsort_s gmtime_s localtime_s ' + +'asctime_s ctime_s getenv_s feenableexcept ' + +'mbsrtowcs_s mbstowcs_s wcsrtombs_s wcstombs_s ' + +'wcrtomb_s wctomb_s wcsnlen_s wcscpy_s wcsncpy_s wcscat_s wcsncat_s ' + +'wmemcpy_s wmemmove_s wcstok_s vswprintf_s swprintf_s vfwprintf_s ' + +'vwprintf_s wprintf_s snwprintf_s fwprintf_s swscanf_s vswscanf_s wscanf_s ' + +'vfwscanf_s fwscanf_s vwscanf_s vsnwprintf_s wcsstr_s wmemcmp_s ' + +'wcscmp_s wcsncmp_s wcsicmp_s wcsset_s wcsnset_s wcscoll_s wcslwr_s ' + +'wcsupr_s towfc_s wcsfc_s ' + +'_swprintf_s_chk _vfwprintf_s_chk').split(' ') +foreach f : funcs + conf.set('HAVE_@0@'.format(f.underscorify().to_upper()), cc.has_function(f)) +endforeach + +headers = [ + 'sys/time.h', + 'stdlib.h', + 'memory.h', + 'ctype.h', + 'malloc.h', + 'string.h', + 'limits.h', + 'stddef.h', + 'unistd.h', + 'float.h', + 'math.h', + 'sys/types.h', + 'inttypes.h', + 'stdint.h', + 'errno.h', + 'wchar.h', + 'langinfo.h', + 'valgrind/valgrind.h', + 'fenv.h', + 'intrin.h', + 'xmmintrin.h', + 'emmintrin.h', + 'x86intrin.h', + 'arm_neon.h', + 'arm_acle.h', + 'mmintrin.h', + 'altivec.h', + 'spe.h', + 'mbarrier.h', +] +foreach h : headers + conf.set('HAVE_@0@'.format(h.underscorify().to_upper()), cc.check_header(h)) +endforeach + +sizeofs = ['size_t', 'wchar_t', 'time_t'] +foreach s : sizeofs + conf.set('SIZEOF_@0@'.format(s.underscorify().to_upper()), cc.sizeof(s)) +endforeach + +conf.set( + 'HAVE_TM_GMTOFF', + cc.has_member( + 'struct tm', + 'tm_gmtoff', + prefix: '#include ', + ), +) +conf.set('HAVE_FLOAT128', cc.compiles('int main(void) { __float128 x = 1.0Q; }')) +conf.set( + 'HAVE_TOWUPPER_OK', + cc.run( + ''' +#include +int main(void) { + return (towupper(0x1C80) == 0x412 + && towupper(0xB5) == 0x3BC + && towupper(0x432) == 0x1C80) + ? 0 : 1; +} +''', + ).returncode() == 0, +) +conf.set( + 'HAVE_STRNSTR_OK', + cc.run( + ''' +#include +int main(void) { + return strnstr("%s %n", "%n", 6) ? 0 : 1; +} +''', + ).returncode() == 0 ? '1' : false, +) + +conf.set( + 'PRINTF_DISABLE_SUPPORT_FLOAT', + get_option('float').allowed() ? false : 1, +) +conf.set( + 'PRINTF_DISABLE_SUPPORT_EXPONENTIAL', + get_option('float-exp').allowed() ? false : 1, +) +conf.set( + 'PRINTF_DISABLE_SUPPORT_LONG_LONG', + get_option('long-long').allowed() ? false : 1, +) +conf.set( + 'PRINTF_DISABLE_SUPPORT_LONG_DOUBLE', + get_option('long-double').allowed() ? false : 1, +) +conf.set( + 'PRINTF_DISABLE_SUPPORT_PTRDIFF_T', + get_option('printf-ptrdiff').allowed() ? false : 1, +) + +conf.set( + 'INSERT_EXTS', + get_option('extensions').allowed() ? '#undef SAFECLIB_DISABLE_EXTENSIONS' : '#define SAFECLIB_DISABLE_EXTENSIONS 1', +) +conf.set( + 'INSERT_NULLSLACK', + get_option('nullslack').allowed() ? '#define SAFECLIB_STR_NULL_SLACK 1' : '#undef SAFECLIB_STR_NULL_SLACK', +) +conf.set( + 'INSERT_CONSTRAINT_HANDLER', + get_option('constraint-handler').allowed() ? '#undef SAFECLIB_DISABLE_CONSTRAINT_HANDLER' : '#define SAFECLIB_DISABLE_CONSTRAINT_HANDLER 1', +) +conf.set( + 'INSERT_UNSAFE', + get_option('unsafe').allowed() ? '#define SAFECLIB_ENABLE_UNSAFE 1' : '#undef SAFECLIB_ENABLE_UNSAFE', +) +haveBuiltinObjectSize = cc.has_function('__builtin_object_size') +conf.set('HAVE___BUILTIN_OBJECT_SIZE', haveBuiltinObjectSize ? '1' : false) +conf.set( + 'INSERT_OBJECT_SIZE', + haveBuiltinObjectSize ? '#define HAVE___BUILTIN_OBJECT_SIZE 1' : '', +) +conf.set( + 'INSERT_WARN_DMAX', + (get_option('warn-dmax').allowed() or get_option('error-dmax').allowed()) and haveBuiltinObjectSize ? '#define HAVE_WARN_DMAX 1' : '', +) +conf.set( + 'INSERT_ERROR_DMAX', + get_option('error-dmax').allowed() and haveBuiltinObjectSize ? '#define HAVE_ERROR_DMAX 1' : '', +) +conf.set( + 'INSERT_DEFAULT_HANDLER', + get_option('default-handler') == 'no' ? '#undef SAFECLIB_DEFAULT_HANDLER' : '#define SAFECLIB_DEFAULT_HANDLER @0@_handler_s'.format( + get_option('default-handler'), + ), +) +conf.set( + 'INSERT_CONSTANT_P', + cc.has_function('__builtin_constant_p') ? '#define HAVE___BUILTIN_CONSTANT_P 1' : '#undef HAVE___BUILTIN_CONSTANT_P', +) +conf.set('INSERT_DISABLE_DLLIMPORT', '#undef DISABLE_DLLIMPORT') +conf.set( + 'INSERT_DISABLE_WCHAR', + get_option('wchar').allowed() ? '#undef SAFECLIB_DISABLE_WCHAR' : '#define SAFECLIB_DISABLE_WCHAR 1', +) +conf.set('INSERT_SAFECLIB_HAVE_C99', '#define SAFECLIB_HAVE_C99 1') +conf.set('RSIZE_MAX_MEM', get_option('memmax')) +conf.set('RSIZE_MAX_STR', get_option('strmax')) +conf.set( + 'FALLBACK_ERRNO_T', + cc.has_type( + 'errno_t', + prefix: '#include ', + ) ? '' : 'typedef int errno_t;', +) +conf.set('HAVE_ATTRIBUTE_FORMAT_WPRINTF', '0') +conf.set('HAVE_ATTRIBUTE_FORMAT_WSCANF', '0') +conf.set('STDC_HEADERS', true) +conf.set('configure_input', '') + +subdir('include') +subdir('src') + +libsafec_dep = declare_dependency( + include_directories: inc, + link_with: libsafec, +) diff --git a/subprojects/packagefiles/safeclib/meson.options b/subprojects/packagefiles/safeclib/meson.options new file mode 100644 index 000000000..57edda519 --- /dev/null +++ b/subprojects/packagefiles/safeclib/meson.options @@ -0,0 +1,105 @@ +option( + 'extensions', + type: 'feature', + description: 'This library contains additional functions not defined in the C11 specification. Disable to omit these.', + value: 'enabled', +) + +option( + 'float', + type: 'feature', + description: 'Enable float support in the printf functions.', + value: 'enabled', +) + +option( + 'float-exp', + type: 'feature', + description: 'Enable exponential floating point notation (%e/%g) in the printf functions.', + value: 'enabled', +) + +option( + 'long-long', + type: 'feature', + description: 'Enable exponential floating point notation (%e/%g) in the printf functions.', + value: 'enabled', +) + +option( + 'long-double', + type: 'feature', + description: 'Enable exponential floating point notation (%e/%g) in the printf functions.', + value: 'enabled', +) + +option( + 'printf-ptrdiff', + type: 'feature', + description: 'Enable ptrdiff_t type (%t) in the printf functions.', + value: 'enabled', +) + +option( + 'memmax', + type: 'integer', + description: 'specify the largest object size allowed for the mem* functions', + value: 268435456, # 256MiB +) + +option( + 'strmax', + type: 'integer', + description: 'specify the largest object size allowed for the str* functions', + value: 4096, # 4KiB +) + +option( + 'nullslack', + type: 'feature', + description: 'Null out the remaining part of a string if it is not completely used', + value: 'enabled', +) + +option( + 'constraint-handler', + type: 'feature', + description: 'Enable C11 invoke_safe_{str,mem}_constraint_handler for performance, smaller size and less flexibility.', + value: 'enabled', +) + +option( + 'unsafe', + type: 'feature', + description: 'Include unsafe std C11 functions: tmpnam_s', + value: 'disabled', +) + +option( + 'warn-dmax', + type: 'feature', + description: 'Enable dmax checks against __builtin_object_size(dest).', + value: 'disabled', +) + +option( + 'error-dmax', + type: 'feature', + description: 'Make --enable-warn-dmax fatal.', + value: 'disabled', +) + +option( + 'default-handler', + type: 'combo', + choices: ['ignore', 'abort', 'no'], + description: 'enforce compile-time default-handler', + value: 'no', +) + +option( + 'wchar', + type: 'feature', + description: 'Enable multibyte and wchar support.', + value: 'enabled', +) diff --git a/subprojects/packagefiles/safeclib/src/meson.build b/subprojects/packagefiles/safeclib/src/meson.build new file mode 100644 index 000000000..89c86516e --- /dev/null +++ b/subprojects/packagefiles/safeclib/src/meson.build @@ -0,0 +1,238 @@ +misc_funcs = ['bsearch_s', 'qsort_s'] +misc_sources = files() +foreach f : misc_funcs + if not cc.has_function(f) + misc_sources += files('misc/@0@.c'.format(f)) + endif +endforeach + +extwchar_funcs = [ + 'wcsstr_s', + 'wcsfc_s', + 'wcscoll_s', + 'wcsicmp_s', + 'towfc_s', + 'wcscmp_s', + 'wcsnatcmp_s', + 'wcsstr', + 'wcsncmp_s', + 'wmemcmp_s', + 'wcsnset_s', + 'wcsset_s', + 'wcsupr_s', + 'wcslwr_s', + 'wcsnorm_s', +] +extwchar_sources = files('extwchar/towctrans.c') +foreach f : extwchar_funcs + if not cc.has_function(f) + extwchar_sources += files('extwchar/@0@.c'.format(f)) + endif +endforeach + +io_funcs = [ + 'fscanf_s', + 'sscanf_s', + 'fprintf_s', + 'gets_s', + 'tmpfile_s', + 'vsscanf_s', + 'vfscanf_s', + 'fopen_s', + 'freopen_s', + 'printf_s', + 'vfprintf_s', + 'vprintf_s', + 'scanf_s', + 'vscanf_s', +] +if get_option('unsafe').allowed() + io_funcs += ['tmpnam_s'] +endif +io_sources = files() +foreach f : io_funcs + if not cc.has_function(f) + io_sources += files('io/@0@.c'.format(f)) + endif +endforeach + +extmem_funcs = [ + 'memchr_s', + 'memmove16_s', + 'memcmp16_s', + 'memzero16_s', + 'memcpy16_s', + 'memset32_s', + 'memset16_s', + 'memcmp_s', + 'memcpy32_s', + 'timingsafe_bcmp', + 'memzero_s', + 'memzero32_s', + 'timingsafe_memcmp', + 'memcmp32_s', + 'memrchr_s', + 'memccpy_s', + 'memmove32_s', +] +extmem_sources = files() +foreach f : extmem_funcs + if not cc.has_function(f) + extmem_sources += files('extmem/@0@.c'.format(f)) + endif +endforeach + +extstr_funcs = [ + 'strlastsame_s', + 'strlastdiff_s', + 'strcoll_s', + 'strchr_s', + 'strismixedcase_s', + 'strstr_s', + 'strpbrk_s', + 'strispassword_s', + 'strisuppercase_s', + 'strremovews_s', + 'strzero_s', + 'strrchr_s', + 'strtouppercase_s', + 'strcasecmp_s', + 'strljustify_s', + 'strfirstsame_s', + 'strcmpfld_s', + 'strfirstdiff_s', + 'strspn_s', + 'strfirstchar_s', + 'strprefix_s', + 'strisascii_s', + 'strnterminate_s', + 'strset_s', + 'strisalphanumeric_s', + 'strcpyfldin_s', + 'strcmp_s', + 'strnset_s', + 'strcpyfldout_s', + 'strisdigit_s', + 'stpncpy_s', + 'strcpyfld_s', + 'strislowercase_s', + 'strcspn_s', + 'strnatcmp_s', + 'stpcpy_s', + 'strtolowercase_s', + 'strlastchar_s', + 'strcasestr_s', + 'strishex_s', +] +extstr_sources = files() +foreach f : extstr_funcs + if not cc.has_function(f) + extstr_sources += files('extstr/@0@.c'.format(f)) + endif +endforeach + +wchar_funcs = [ + 'vsnwprintf_s', + 'swprintf_s', + 'wcstok_s', + 'wcrtomb_s', + 'mbsrtowcs_s', + 'fwscanf_s', + 'wcsnlen_s', + 'swscanf_s', + 'vfwprintf_s', + 'vwprintf_s', + 'snwprintf_s', + 'wcstombs_s', + 'wctomb_s', + 'vfwscanf_s', + 'vwscanf_s', + 'vswscanf_s', + 'fwprintf_s', + 'wprintf_s', + 'wcscat_s', + 'vswprintf_s', + 'wcsrtombs_s', + 'wcsncat_s', + 'wmemmove_s', + 'mbstowcs_s', + 'wcscpy_s', + 'wcsncpy_s', + 'wmemcpy_s', + 'wscanf_s', +] +wchar_sources = files() +foreach f : wchar_funcs + if not cc.has_function(f) + wchar_sources += files('wchar/@0@.c'.format(f)) + endif +endforeach + +os_funcs = ['localtime_s', 'ctime_s', 'asctime_s', 'getenv_s', 'gmtime_s'] +os_sources = files() +foreach f : os_funcs + if not cc.has_function(f) + os_sources += files('os/@0@.c'.format(f)) + endif +endforeach + +str_funcs = [ + 'snprintf_s', + 'sprintf_s', + 'strerror_s', + 'safe_str_constraint', + 'strtok_s', + 'strnlen_s', + 'strcat_s', + 'strncat_s', + 'strncpy_s', + 'vsprintf_s', + 'strcpy_s', + 'vsnprintf_s', +] +str_sources = files() +foreach f : str_funcs + if not cc.has_function(f) + str_sources += files('str/@0@.c'.format(f)) + endif +endforeach + +mem_funcs = [ + 'mem_primitives_lib', + 'memmove_s', + 'memset_s', + 'safe_mem_constraint', + 'memcpy_s', +] +mem_sources = files() +foreach f : mem_funcs + if not cc.has_function(f) + mem_sources += files('mem/@0@.c'.format(f)) + endif +endforeach + +handler_sources = files('abort_handler_s.c', 'ignore_handler_s.c') + +sources = io_sources + os_sources + str_sources + mem_sources + handler_sources + misc_sources +if get_option('extensions').allowed() + sources += extmem_sources + sources += extstr_sources + if get_option('wchar').allowed() + sources += extwchar_sources + endif +endif +if get_option('wchar').allowed() + sources += wchar_sources +endif + +configure_file( + output: 'config.h', + configuration: conf, +) + +libsafec = library( + 'safec', + sources, + install: true, + include_directories: inc, +) diff --git a/subprojects/safeclib.wrap b/subprojects/safeclib.wrap new file mode 100644 index 000000000..87f9044be --- /dev/null +++ b/subprojects/safeclib.wrap @@ -0,0 +1,9 @@ +[wrap-file] +directory = safeclib-3.9.1 +source_url = https://github.com/rurban/safeclib/releases/download/v3.9.1/safeclib-3.9.1.tar.xz +source_filename = safeclib-3.9.1.tar.xz +source_hash = 771b8de483c4f48c90c12bc2c0326571d3d094440ca29008e4cf70562c631c67 +patch_directory = safeclib + +[provide] +libsafec = libsafec_dep