libpkgconf/argvsplit.c


Log

Author Commit Date CI Message
Ariadne Conill 1fd56779 2025-05-28T23:15:52 libpkgconf: argvsplit: use calloc for all buffers, handle memory alloc failures Found-by: GCC -fanalyzer Signed-off-by: Ariadne Conill <ariadne@ariadne.space>
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>
huyubiao 6d1f160e 2023-03-06T20:05:22 argvsplit: fix some quoting rules
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.
Ariadne Conill be0d8119 2023-01-21T19:51:24 argvsplit: fix some quoting rules to match POSIX
Ziemowit Łąski 1c3f2461 2022-11-22T12:29:09 pkgconf: Handle spaces correctly when expanding variables Given the following .pc fragment: includedir=/mingw64/include Cflags: -I${includedir} -I${includedir}/taglib Should includedir be assigned the value 'C:/Program\ Files/Git/mingw64/include', the expansion of ${includedir} will be chopped off after the first space: Cflags: -IC:/Program\ With this patch, the expansion is corrected: Cflags: -IC:/Program\ Files/Git/mingw64/include -IC:/Program\ Files/Git/mingw64/include/taglib Create spaces-in-paths.pc
Vincent Torri 42b35531 2020-05-30T12:39:43 fix missing backslashes in paths on Windows According to https://docs.microsoft.com/fr-fr/windows/win32/fileio/naming-a-file backslashes (with slashes) are a path separator, hence must no be considered as an escape code. The first fix, in argvsplit.c, disables this. But because of fragment_quote(), the backslashes are doubled. Hence the second fix in fragment.c With this pc file : prefix=C:/Documents/msys2/opt/efl_64 libdir=${prefix}/lib includedir=${prefix}/include Name: eina Description: efl: eina Version: 1.24.99 Requires.private: iconv Libs: -L${libdir} -leina -pthread -levil Libs.private: -lpsapi -lole32 -lws2_32 -lsecur32 -luuid -lregex -lm Cflags:-I${includedir}/eina-1 -I${includedir}/efl-1 -I${includedir}/eina-1/eina -pthread pkgconf.exe --cflags eina returns : -IC:\Documents\msys2\opt\efl_64/include/eina-1 -IC:\Documents\msys2\opt\efl_64/include/efl-1 -IC:\Documents\msys2\opt\efl_64/include/eina-1/eina -pthread -DWINICONV_CONST= -IC:\Documents\msys2\opt\ewpi_64/include
William Pitcock cf96c562 2017-12-14T22:41:14 libpkgconf: argvsplit: fix escape handling in tokenizer (closes #163)
William Pitcock 278a2bd6 2017-12-11T18:25:55 libpkgconf: fragment: rework quoting and lexing (closes #139, #153) we now use POSIX-style quoting for all fragments. it is our belief that this is the most optimal behaviour for portability, because all POSIX-compliant tools require single-quotes to be considered as literal (closes #153). because of this, we are able to remove some hacks on the lexer side which were there to simulate pkg-config quoting, but were basically utterly wrong (closes #139).
William Pitcock fae65710 2017-09-23T00:24:34 libpkgconf: argvsplit: handle double backslash case properly (closes #140)
William Pitcock e9fd43ca 2017-09-17T23:38:25 libpkgconf: clean up header includes (closes #137)
William Pitcock 6e643aa4 2017-03-29T18:00:57 libpkgconf: hopefully the last necessary tweak to quoting...
William Pitcock ae42261c 2017-02-25T15:04:08 argvsplit: refactor splitting state machine
William Pitcock d558e30a 2017-02-07T10:24:54 libpkgconf: argvsplit: quoting logic was simplified too much
William Pitcock fe40bc33 2017-02-03T12:53:50 libpkgconf: argvsplit: do not consider ' or " to be equivalent to \ (#111)
William Pitcock 67796a1d 2017-01-22T23:04:01 libpkgconf: argvsplit: make escape handling more explicit
William Pitcock 828c2902 2016-12-10T18:56:09 libpkgconf: document argvsplit module
Baptiste Daroussin 7898b829 2015-12-02T12:50:04 Correctly cast ctypes function input to unsigned int This fixes issues found by building on NetBSD which is more pedantic about thoses cases. Reported by: Thomas Klausner (wiz at NetBSD)
William Pitcock abbd6b06 2015-09-27T16:07:06 Revert "Merge pull request #81 from dankegel/quotefest" This reverts commit 42551f6364ab0e024e68ed03ef39c9688140fc88, reversing changes made to 938bb9e694c6d377bad29a0fa6856d6ce98c8033.
Dan Kegel d0bbc686 2015-09-10T16:49:52 Add tests for libraries quoted with double quotes, make them pass
William Pitcock b17f2640 2015-09-06T10:48:24 libpkgconf: move some utility funcs into pkgconf_ namespace
William Pitcock a706b3dc 2015-09-06T09:35:08 initial libtoolization for libpkgconf