libpkgconf/personality.c


Log

Author Commit Date CI Message
Kai Pastor fea9592a 2025-06-12T08:34:29 personality.c: _WIN32 does not want_default_static
Ariadne Conill 5ecd34e4 2025-05-28T22:10:10 libpkgconf: personality: rework non-default personality loading If there is an error loading the personality file (for example, the personality file associated with the requested triplet does not exist), then resources would be leaked. Found-by: GCC -fanalyzer Signed-off-by: Ariadne Conill <ariadne@ariadne.space>
Ariadne Conill 444846dd 2024-10-07T17:44:22 personality: drop want_default_pure on windows We still retain want_default_static to satisfy the requirements of the PE/COFF linking model. Fixes: 008d7069 ("libpkgconf: personality: default: set want_default_static and want_default_pure to true on windows") Signed-off-by: Ariadne Conill <ariadne@dereferenced.org> Closes: #364
Victor Westerhuis 948297b5 2023-10-31T14:09:55 Search XDG Base Directories for personality files Try $XDG_DATA_HOME/pkgconfig/personality.d and $XDG_DATA_DIRS/pkgconfig/personality.d.
Sam James d454f62c 2023-11-05T22:17:02 libpkgconf: fix -Walloc-size GCC 14 introduces a new -Walloc-size included in -Wextra which gives: ``` libpkgconf/personality.c:260:11: warning: allocation of insufficient size '1' for type 'pkgconf_cross_personality_t' {aka 'struct pkgconf_cross_personality_'} with size '48' [-Walloc-size] libpkgconf/queue.c:46:33: warning: allocation of insufficient size '1' for type 'pkgconf_queue_t' {aka'struct pkgconf_queue_'} with size '16' [-Walloc-size] libpkgconf/client.c:164:33: warning: allocation of insufficient size '1' for type 'pkgconf_client_t' {aka 'struct pkgconf_client_'} with size '120' [-Walloc-size] libpkgconf/path.c:105:14: warning: allocation of insufficient size '1' for type 'pkgconf_path_t' {aka 'struct pkgconf_path_'} with size '24' [-Walloc-size] libpkgconf/path.c:237:22: warning: allocation of insufficient size '1' for type 'pkgconf_path_t' {aka 'struct pkgconf_path_'} with size '24' [-Walloc-size] libpkgconf/tuple.c:239:34: warning: allocation of insufficient size '1' for type 'pkgconf_tuple_t' {aka 'struct pkgconf_tuple_'} with size '24' [-Walloc-size] libpkgconf/dependency.c:133:13: warning: allocation of insufficient size '1' for type 'pkgconf_dependency_t' {aka 'struct pkgconf_dependency_'} with size '44' [-Walloc-size] libpkgconf/dependency.c:472:17: warning: allocation of insufficient size '1' for type 'pkgconf_dependency_t' {aka 'struct pkgconf_dependency_'} with size '44' [-Walloc-size] libpkgconf/fragment.c:146:22: warning: allocation of insufficient size '1' for type 'pkgconf_fragment_t' {aka 'struct pkgconf_fragment_'} with size '24' [-Walloc-size] libpkgconf/fragment.c:195:22: warning: allocation of insufficient size '1' for type 'pkgconf_fragment_t' {aka 'struct pkgconf_fragment_'} with size '24' [-Walloc-size] libpkgconf/fragment.c:356:14: warning: allocation of insufficient size '1' for type 'pkgconf_fragment_t' {aka 'struct pkgconf_fragment_'} with size '24' [-Walloc-size] libpkgconf/pkg.c:422:13: warning: allocation of insufficient size '1' for type 'pkgconf_pkg_t' {aka 'struct pkgconf_pkg_'} with size '188' [-Walloc-size] libpkgconf/client.c:164:33: warning: allocation of insufficient size '1' for type 'pkgconf_client_t' {aka 'struct pkgconf_client_'} with size '224' [-Walloc-size] libpkgconf/personality.c:260:11: warning: allocation of insufficient size '1' for type 'pkgconf_cross_personality_t' {aka 'struct pkgconf_cross_personality_'} with size '96' [-Walloc-size] libpkgconf/dependency.c:133:13: warning: allocation of insufficient size '1' for type 'pkgconf_dependency_t' {aka 'struct pkgconf_dependency_'} with size '80' [-Walloc-size] libpkgconf/dependency.c:472:17: warning: allocation of insufficient size '1' for type 'pkgconf_dependency_t' {aka 'struct pkgconf_dependency_'} with size '80' [-Walloc-size] libpkgconf/path.c:105:14: warning: allocation of insufficient size '1' for type 'pkgconf_path_t' {aka 'struct pkgconf_path_'} with size '48' [-Walloc-size] libpkgconf/path.c:237:22: warning: allocation of insufficient size '1' for type 'pkgconf_path_t' {aka 'struct pkgconf_path_'} with size '48' [-Walloc-size] libpkgconf/queue.c:46:33: warning: allocation of insufficient size '1' for type 'pkgconf_queue_t' {aka 'struct pkgconf_queue_'} with size '32' [-Walloc-size] libpkgconf/tuple.c:239:34: warning: allocation of insufficient size '1' for type 'pkgconf_tuple_t' {aka 'struct pkgconf_tuple_'} with size '48' [-Walloc-size] libpkgconf/fragment.c:146:22: warning: allocation of insufficient size '1' for type 'pkgconf_fragment_t' {aka 'struct pkgconf_fragment_'} with size '48' [-Walloc-size] libpkgconf/fragment.c:195:22: warning: allocation of insufficient size '1' for type 'pkgconf_fragment_t' {aka 'struct pkgconf_fragment_'} with size '48' [-Walloc-size] libpkgconf/fragment.c:356:14: warning: allocation of insufficient size '1' for type 'pkgconf_fragment_t' {aka 'struct pkgconf_fragment_'} with size '48' [-Walloc-size] libpkgconf/pkg.c:422:13: warning: allocation of insufficient size '1' for type 'pkgconf_pkg_t' {aka 'struct pkgconf_pkg_'} with size '360' [-Walloc-size] ``` The calloc prototype is: ``` void *calloc(size_t nmemb, size_t size); ``` So, just swap the number of members and size arguments to match the prototype, as we're initialising 1 struct of size `sizeof(struct ...)`. GCC then sees we're not doing anything wrong. The only exception there is for argv which I fixed while at it. Signed-off-by: Sam James <sam@gentoo.org>
Taylor R Campbell 212c8586 2023-03-17T19:32:58 Avoid undefined behaviour with the ctype(3) functions. fix https://github.com/pkgconf/pkgconf/issues/291 As defined in the C standard: In all cases the argument is an int, the value of which shall be representable as an unsigned char or shall equal the value of the macro EOF. If the argument has any other value, the behavior is undefined. This is because they're designed to work with the int values returned by getc or fgetc; they need extra work to handle a char value. If EOF is -1 (as it almost always is), with 8-bit bytes, the allowed inputs to the ctype(3) functions are: {-1, 0, 1, 2, 3, ..., 255}. However, on platforms where char is signed, such as x86 with the usual ABI, code like char *ptr = ...; ... isspace(*ptr) ... may pass in values in the range: {-128, -127, -126, ..., -2, -1, 0, 1, ..., 127}. This has two problems: 1. Inputs in the set {-128, -127, -126, ..., -2} are forbidden. 2. The non-EOF byte 0xff is conflated with the value EOF = -1, so even though the input is not forbidden, it may give the wrong answer. Casting char to unsigned int first before passing the result to ctype(3) doesn't help: inputs like -128 are unchanged by this cast, because (on a two's-complement machine with 32-bit int and unsigned int), converting the signed char with integer value -128 to unsigned int gives integer value 2^32 - 128 = 0xffffff80, which is out of range, and which is converted in int back to -128, which is also out of range. It is necessary to cast char inputs to unsigned char first; you can then cast to unsigned int if you like but there's no need because the functions will always convert the argument to int by definition. So the above fragment needs to be: char *ptr = ...; ... isspace((unsigned char)*ptr) ... This patch changes unsigned int casts to unsigned char casts, and adds unsigned char casts where they are missing.
Andrej Shadura 9ab5ea2e 2023-01-22T11:49:54 doc: personality: Add a documentation header Signed-off-by: Andrej Shadura <andrew.shadura@collabora.co.uk>
Dylan Baker c581e24a 2022-02-10T19:46:19 personality: use an unsigned to track initializations Instead of a bool. The latter will result in de-initing leaving the library unable to init again, which works out for the cli, but is problematic for other consumers (meson++ and muon). v2: - Add docs that the functions are not thread safe
Ariadne Conill 78bcb171 2021-07-24T20:06:55 personality: do not perform path filtering on default SYSTEM_INCLUDE_PATHS and SYSTEM_LIBRARY_PATHS This is not consistent with the way the personality files or environment variables are handled. Fixes #224.
Stone Tickle d688a7bd 2021-06-11T15:00:47 implement pkgconf_cross_personality_deinit
Ariadne Conill 008d7069 2021-03-18T06:03:32 libpkgconf: personality: default: set want_default_static and want_default_pure to true on windows
Ariadne Conill f9531ce9 2021-03-18T05:59:54 add support for pkgconf_cross_personality_t.want_default_pure
Tobias Stoeckmann 9e16d270 2020-05-24T23:13:19 libpkgconf: personality: fix out of boundary access It is possible to set the instruction pointer to undefined values by using an operator larger than ':' in ASCII. Since the personality function array does not have 256 entries, an invalid operator can overflow the array. Proof of concept: $ echo "a _ b" > poc $ ln -s $(which pkgconf) poc-pkgconf $ ./poc-pkgconf
Ariadne Conill 48dc665a 2019-10-19T00:56:17 personality: add support for WantDefaultStatic setting
Ariadne Conill 2adafc27 2019-08-23T12:47:22 libpkgconf: personality: return the default personality if loading a personality file failed
Alexander Tsoy db9c1e96 2019-06-07T19:19:28 fix the order of header includes config.h should be included before stdinc.h, otherwise large file support is not enabled. Downstream bug: https://bugs.gentoo.org/687548
William Pitcock 43ca536b 2019-05-06T15:13:17 lite: disable some bloat
Ignacio Casal Quinteiro c9dffb85 2018-09-17T15:19:18 Fix build on windows with meson
Graham Ollis 273d1d04 2018-05-29T17:36:04 use pkgconf_strlcpy On Debian/Ubuntu I get: CC libpkgconf/personality.lo libpkgconf/personality.c: In function ‘load_personality_with_path’: libpkgconf/personality.c:195:3: warning: implicit declaration of function ‘strlcpy’ [-Wimplicit-function-declaration] strlcpy(pathbuf, path, sizeof pathbuf); ^~~~~~~ CC libpkgconf/parser.lo CCLD libpkgconf.la ar: `u' modifier ignored since `D' is the default (see `U') CC cli/pkgconf-main.o CC cli/pkgconf-getopt_long.o CC cli/pkgconf-renderer-msvc.o CCLD pkgconf ./.libs/libpkgconf.so: undefined reference to `strlcpy'
William Pitcock 3ccc4454 2018-05-10T13:36:22 libpkgconf: personality: ensure the path list is properly initialized before searching for triplets
William Pitcock 40897f24 2018-05-09T22:52:27 libpkgconf: personality: remove const from the default personality, since it's not really const
William Pitcock e6ce6c8e 2018-05-09T22:39:39 libpkgconf: personality: fixups
William Pitcock 75134829 2018-05-09T22:08:28 libpkgconf: personality: fill in the rest of the personality parser
William Pitcock 9439b683 2018-05-09T19:27:53 libpkgconf: personality: add stub cross personality loader
William Pitcock 6b0e346c 2018-05-09T17:07:26 libpkgconf: refactor building the dir lists into separate concerns
William Pitcock 854490c5 2018-05-09T16:54:21 libpkgconf: add basic support for cross-compile personality objects