glib/tests
Philip Withnall fc25f8d7ef gfileutils: Correctly reset start value when canonicalising paths
If a path starts with more than two slashes, the `start` value was
previously incorrect:
 1. As per the `g_path_skip_root()` call, `start` was set to point to
    after the final initial slash. For a path with three initial
    slashes, this is the character after the third slash.
 2. The canonicalisation loop to find the first dir separator sets
    `output` to point to the character after the first slash (and it
    overwrites the first slash to be `G_DIR_SEPARATOR`).
 3. At this point, with a string `///usr`, `output` points to the second
    `/`; and `start` points to the `u`. This is incorrect, as `start`
    should point to the starting character for output, as per the
    original call to `g_path_skip_root()`.
 4. For paths which subsequently include a `..`, this results in the
    `output > start` check in the `..` loop below not skipping all the
    characters of a preceding path component, which is then caught by
    the `G_IS_DIR_SEPARATOR (output[-1])` assertion.

Fix this by resetting `start` to `output` after finding the final slash
to keep in the output, but before starting the main parsing loop.

Relatedly, split `start` into two variables: `after_root` and
`output_start`, since the variable actually has two roles in the two
parts of the function.

Includes a test.

This commit is heavily based on suggestions by Sebastian Wilhemi and
Sebastian Dröge.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

oss-fuzz#41563
2021-12-02 17:50:17 +00:00
..
collate Add Collation tests. 2005-10-05 17:37:46 +00:00
gobject gobject: Allow passing %NULL for @data in g_object_remove_toggle_ref 2021-05-27 21:09:45 +05:30
refcount Fix signedness warnings in tests/refcount/objects.c 2021-05-04 08:43:29 +02:00
assert-msg-test.c Normalize C source files to end with exactly one newline 2020-06-10 09:48:02 +01:00
assert-msg-test.gdb tests: Work around a gdb bug in assert-msg-test 2017-11-27 11:44:08 +00:00
casefold.txt glib: Update Unicode Character Database to version 13.0.0 2020-03-18 14:50:36 +00:00
casemap.txt glib: Update Unicode Character Database to version 13.0.0 2020-03-18 14:50:36 +00:00
child-test.c all: Remove trailing newlines from g_message()/g_warning()/g_error()s 2018-04-27 16:46:19 +01:00
completion-test.c tests/: LGPLv2+ -> LGPLv2.1+ 2017-05-29 19:53:35 +02:00
cxx-test.cpp Rename cxx-test.C to cxx-test.cpp 2018-09-21 08:45:54 -04:00
datetime.c Revert "gdatetime: Enable compile time check of g_date_time_format() format" 2018-11-01 16:12:32 +00:00
dirname-test.c Fix signedness warning in tests/dirname-test.c 2021-05-04 08:45:56 +02:00
env-test.c tests/: LGPLv2+ -> LGPLv2.1+ 2017-05-29 19:53:35 +02:00
file-test.c tests/: LGPLv2+ -> LGPLv2.1+ 2017-05-29 19:53:35 +02:00
gen-casefold-txt.py py: Reformat all Python files consistently 2020-11-17 15:50:07 +00:00
gen-casemap-txt.py py: Various flake8 cleanups 2020-11-17 15:50:07 +00:00
gio-test.c Fix signedness warnings in tests/gio-test.c 2021-05-06 14:35:20 +02:00
iochannel-test-infile Modified Files: glib/ChangeLog glib/glib.def glib/glib/giochannel.c 2001-07-20 20:14:37 +00:00
iochannel-test.c iochannel-test: Fix leaks in test 2013-11-10 22:45:04 +01:00
libmoduletestplugin_a.c tests/: LGPLv2+ -> LGPLv2.1+ 2017-05-29 19:53:35 +02:00
libmoduletestplugin_b.c tests/: LGPLv2+ -> LGPLv2.1+ 2017-05-29 19:53:35 +02:00
mainloop-test.c Port internal uses to use g_source_set_static_name() 2021-07-26 11:01:07 +01:00
mapping-test.c tests W32: ifdef a variable not used on Windows 2018-09-21 08:45:54 -04:00
memchunks.c Fix signedness warning in tests/memchunks.c 2021-05-06 22:54:53 +02:00
meson.build Merge branch 'move_bit-test' into 'main' 2021-12-02 09:45:37 +00:00
module-test.c giomodule: Port to new g_module_open_full() API 2021-07-21 21:54:35 +01:00
onceinit.c Fix signedness warning in tests/onceinit.c 2021-04-29 12:40:05 +02:00
relation-test.c Normalize C source files to end with exactly one newline 2020-06-10 09:48:02 +01:00
run-assert-msg-test.sh Correct shellcheck errors (and ignore world splitting when we want it) 2020-11-15 17:34:27 +01:00
run-collate-tests.sh build: Fix shellcheck warnings in various old build and test scripts 2020-02-27 10:33:45 +00:00
slice-color.c tests/: LGPLv2+ -> LGPLv2.1+ 2017-05-29 19:53:35 +02:00
slice-concurrent.c tests/: LGPLv2+ -> LGPLv2.1+ 2017-05-29 19:53:35 +02:00
slice-test.c slice-test: Use new g_newa0() function 2021-11-26 12:24:23 +00:00
slice-threadinit.c Fix missing initializer warning in tests/slice-threadinit.c 2021-05-27 10:16:52 +02:00
spawn-test-win32-gui.c gspawn, tests: extend spawn_test, run it on win32 2018-12-26 23:45:47 +03:00
spawn-test.c gspawn, tests: extend spawn_test, run it on win32 2018-12-26 23:45:47 +03:00
testgdate.c testgdate: fix -Wmisleading-indentation warning 2021-06-16 12:22:28 -05:00
testgdateparser.c Normalize C source files to end with exactly one newline 2020-06-10 09:48:02 +01:00
testglib.c gfileutils: Correctly reset start value when canonicalising paths 2021-12-02 17:50:17 +00:00
thread-test.c Fix signedness warning in tests/thread-test.c 2021-05-06 22:54:53 +02:00
threadpool-test.c Fix several signedness warnings in tests/threadpool-test.c 2021-05-06 22:54:53 +02:00
timeloop-basic.c Normalize C source files to end with exactly one newline 2020-06-10 09:48:02 +01:00
timeloop.c Fix signedness warning in tests/timeloop.c 2021-05-04 16:13:41 +02:00
type-test.c win32: don't assume the format specifier for the stdlib printf/scanf like functions 2019-08-10 21:56:33 +02:00
unicode-caseconv.c tests: Port gen-casefold-txt.pl and gen-casemap-txt.pl to Python 3. See #1332 2018-06-12 22:18:03 +02:00
unicode-collate.c Fix signedness warning in tests/unicode-collate.c 2021-05-06 14:35:46 +02:00
unicode-encoding.c Fix several signedness warnings in tests/unicode-encoding.c 2021-05-06 22:54:53 +02:00
unicode-normalize.c Update to reflect Unicode PR #29 (#348694, Nikolai Weibull) 2006-07-31 04:50:05 +00:00
utf8.txt More clean up for Unicode corrigendum #9 2013-03-18 23:28:27 -04:00