pkgconf/tests/lib1
Taylor R Campbell 212c85863a 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.
2023-05-02 11:43:56 -07:00
..
argv-parse-2.pc testsuite: use /test as an explicit prefix on all tests 2015-07-20 03:10:27 -05:00
argv-parse-3.pc testsuite: use /test as an explicit prefix on all tests 2015-07-20 03:10:27 -05:00
argv-parse.pc testsuite: use /test as an explicit prefix on all tests 2015-07-20 03:10:27 -05:00
bar.pc testsuite: use /test as an explicit prefix on all tests 2015-07-20 03:10:27 -05:00
baz.pc testsuite: use /test as an explicit prefix on all tests 2015-07-20 03:10:27 -05:00
billion-laughs.pc add billion-laughs test fixture 2023-01-20 22:01:38 +00:00
case-sensitivity.pc tests: add test for variable case-sensitivity (ref #60) 2014-02-10 23:50:45 +00:00
cflags-internal.pc tests: add new test fixtures for Requires.internal 2018-03-18 18:00:04 -05:00
cflags-libs-only.pc testsuite: use /test as an explicit prefix on all tests 2015-07-20 03:10:27 -05:00
cflags-whitespace-trailing.pc testsuite: add a test for #99 2016-10-25 14:03:25 -05:00
cflags-whitespace.pc testsuite: add tests for normal fragments and whitespace munging, too (closes #94) 2016-08-24 19:00:10 -05:00
circular-1.pc testsuite: use /test as an explicit prefix on all tests 2015-07-20 03:10:27 -05:00
circular-2.pc testsuite: use /test as an explicit prefix on all tests 2015-07-20 03:10:27 -05:00
circular-3.pc testsuite: use /test as an explicit prefix on all tests 2015-07-20 03:10:27 -05:00
comments-in-fields.pc testsuite: fix comments in fields testcase 2015-04-20 09:23:13 -05:00
comments.pc testsuite: regression test for parsing comments 2015-04-23 22:01:00 +02:00
conflicts.pc testsuite: use /test as an explicit prefix on all tests 2015-07-20 03:10:27 -05:00
depgraph-break.pc testsuite: add a test for explicit depgraph breakage 2016-05-19 17:37:27 -05:00
dos-lineendings.pc testsuite: use /test as an explicit prefix on all tests 2015-07-20 03:10:27 -05:00
empty-tuple.pc regress: add test for empty tuple buffer overflow issue 2018-07-28 19:45:57 -05:00
escaped-backslash.pc tests: add testcase for #140 2017-09-23 00:08:12 -05:00
explicit-sysroot.pc tests: add test for github #123 2017-07-16 17:33:42 -05:00
flag-order-1.pc tests: add tests for the fragment mergeback changes 2016-12-30 12:45:29 -06:00
flag-order-3.pc tests: add tests for the fragment mergeback changes 2016-12-30 12:45:29 -06:00
foo.pc tests: add tests for SPDX license assertions 2022-08-07 04:40:31 +00:00
fragment-collision-1.pc tests: add reduced version of freebsd gtk+-3.0 crappy output situation as a testcase 2017-05-05 01:40:09 -05:00
fragment-collision-2.pc tests: add reduced version of freebsd gtk+-3.0 crappy output situation as a testcase 2017-05-05 01:40:09 -05:00
fragment-collision-intermediary.pc tests: add reduced version of freebsd gtk+-3.0 crappy output situation as a testcase 2017-05-05 01:40:09 -05:00
fragment-collision.pc tests: add reduced version of freebsd gtk+-3.0 crappy output situation as a testcase 2017-05-05 01:40:09 -05:00
fragment-comment.pc tests: add fragment-comment testcase (ref #215) 2021-03-18 05:39:45 -06:00
fragment-escaping-1.pc msvc: handle quoting correctly for cmd.exe 2018-01-05 11:31:43 -06:00
fragment-escaping-2.pc tests: add testcases for #163 2017-12-14 22:13:19 -06:00
fragment-escaping-3.pc tests: add testcases for #163 2017-12-14 22:13:19 -06:00
fragment-quoting-2.pc libpkgconf: argvsplit: quoting logic was simplified too much 2017-02-07 10:25:38 -06:00
fragment-quoting-3.pc libpkgconf: argvsplit: quoting logic was simplified too much 2017-02-07 10:25:38 -06:00
fragment-quoting-5.pc testsuite: add testsuite cases for inverse quoting situations 2017-02-25 13:57:38 -06:00
fragment-quoting-7.pc tests: back out go-style test, just verify the output because shells are terrible 2017-03-29 18:00:10 -05:00
fragment-quoting.pc testsuite: add regression test for #111 2017-02-03 12:58:11 -06:00
framework-1.pc testsuite: use /test as an explicit prefix on all tests 2015-07-20 03:10:27 -05:00
framework-2.pc testsuite: use /test as an explicit prefix on all tests 2015-07-20 03:10:27 -05:00
idirafter-ordering.pc tests: regress: add another test case for -idirafter ordering (noticed on pkg-config bugzilla) 2016-12-30 20:25:02 -06:00
idirafter.pc libpkgconf: fragment: handle -idirafter in the same way as -isystem 2016-12-30 02:47:42 -06:00
incomplete.pc tests: add test for freedesktop.org bug 54271 2012-09-02 17:46:00 -05:00
intermediary-1.pc testsuite: use /test as an explicit prefix on all tests 2015-07-20 03:10:27 -05:00
intermediary-2.pc testsuite: use /test as an explicit prefix on all tests 2015-07-20 03:10:27 -05:00
isystem.pc testsuite: add a test for #87 2016-05-19 16:47:11 -05:00
malformed-1.pc libpkgconf: pkgconf_pkg_find(): correctly handle failure from pkgconf_pkg_new_from_file() 2017-05-19 23:33:49 -05:00
malformed-quoting.pc tests: regress: add malformed quoting test 2017-09-19 21:35:18 -05:00
malformed-version.pc tests: add malformed-version fixture 2019-07-12 06:15:35 -05:00
metapackage-1.pc tests: add fixtures for github #258 2022-08-08 05:26:00 +00:00
metapackage-2.pc tests: add fixtures for github #258 2022-08-08 05:26:00 +00:00
metapackage.pc tests: add fixtures for github #258 2022-08-08 05:26:00 +00:00
missing-require.pc testsuite: use /test as an explicit prefix on all tests 2015-07-20 03:10:27 -05:00
multiline-bogus.pc tests: add test fixture for bogus .pc files 2018-06-16 16:35:19 -05:00
multiline.pc testsuite: use /test as an explicit prefix on all tests 2015-07-20 03:10:27 -05:00
no-trailing-newline.pc testsuite: use /test as an explicit prefix on all tests 2015-07-20 03:10:27 -05:00
nocflag.pc testsuite: use /test as an explicit prefix on all tests 2015-07-20 03:10:27 -05:00
nolib.pc testsuite: use /test as an explicit prefix on all tests 2015-07-20 03:10:27 -05:00
omg-sysroot-uninstalled.pc tests: add omg-sysroot-uninstalled fixture 2022-07-26 18:03:15 +00:00
omg-uninstalled.pc testsuite: use /test as an explicit prefix on all tests 2015-07-20 03:10:27 -05:00
orphaned-requires-private.pc tests: add orphaned requires.private testcase 2019-01-14 14:04:50 -06:00
paren-quoting.pc tests: add test for #67 2014-07-01 23:30:59 -05:00
prefix-foo1.pc testsuite: use /test as an explicit prefix on all tests 2015-07-20 03:10:27 -05:00
prefix-foo2.pc testsuite: use /test as an explicit prefix on all tests 2015-07-20 03:10:27 -05:00
private-libs-duplication.pc tests: fix validation on private-libs-duplication test 2015-05-21 22:14:08 -05:00
provides-request-simple.pc pkg: add support for 'simple' Provides rule entries (#95) 2016-09-08 22:10:24 -05:00
provides.pc tests: provides: provide a PKG_CMP_NOT_EQUAL dependency node 2016-09-09 14:45:33 -05:00
quotes.pc Revert "Merge pull request #81 from dankegel/quotefest" 2015-09-27 16:10:33 -05:00
requires-internal-2.pc tests: add new test fixtures for Requires.internal 2018-03-18 18:00:04 -05:00
requires-internal-collision.pc libpkgconf: dependency: preference uncoloured nodes in event of a dependency collision 2018-03-18 19:03:18 -05:00
requires-internal-missing.pc tests: add new test fixtures for Requires.internal 2018-03-18 18:00:04 -05:00
requires-internal.pc tests: add new test fixtures for Requires.internal 2018-03-18 18:00:04 -05:00
spaces-in-paths.pc pkgconf: Handle spaces correctly when expanding variables 2023-01-20 22:18:26 +00:00
static-archive-libs.pc testsuite: use /test as an explicit prefix on all tests 2015-07-20 03:10:27 -05:00
static-libs.pc testsuite: use /test as an explicit prefix on all tests 2015-07-20 03:10:27 -05:00
sysroot-dir-2.pc add additional sysroot testcase fixtures 2022-06-26 19:21:52 +00:00
sysroot-dir-3.pc tests: add additional test fixtures 2022-06-26 19:34:39 +00:00
sysroot-dir-4.pc tests: add additional test fixtures 2022-06-26 19:34:39 +00:00
sysroot-dir-5.pc tests: add additional test fixtures 2022-06-26 19:34:39 +00:00
sysroot-dir.pc fragments: handle sysroot dir munging directly in a smarter way 2014-07-09 01:23:51 -05:00
tilde-quoting.pc testsuite: add a test for tilde quoting 2013-02-24 07:04:15 -06:00
tilde.pc testsuite: use /test as an explicit prefix on all tests 2015-07-20 03:10:27 -05:00
tuple-quoting.pc tests: add testcase for tuple dequoting bug (legacy github bug #186) 2018-06-14 16:11:21 -05:00
typelibdir.pc Add a regression tests about define-variable 2015-12-07 23:36:45 +01:00
utf8.pc Avoid undefined behaviour with the ctype(3) functions. 2023-05-02 11:43:56 -07:00
variable-whitespace.pc testsuite: add tests for variable whitespace 2017-01-26 12:55:48 -06:00