From 92791a3fe15bb2d5c14039fbd531be73255f0c6d Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Sat, 1 Jun 2019 04:15:04 +0200 Subject: Fix obscure crash with rsource and $srctree pointing to a symlink Sourcing a file with an absolute path and using rsource in it triggered a relpath() between the absolute path and $srctree. Since e.g. symlink/../bar/ = bar/ is not guaranteed for symlinks, this could lead to the rsource'd file not being found if $srctree pointed to a symlink. Switch to a simpler, more textual method for stripping $srctree from glob results, which should be robust against symlink shenanigans. This also makes the code a bit easier to follow. Discovered by Marc Herbert. Piggyback some minor cleanup. --- testsuite.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'testsuite.py') diff --git a/testsuite.py b/testsuite.py index 9438863..376f165 100644 --- a/testsuite.py +++ b/testsuite.py @@ -1138,12 +1138,26 @@ tests/Krecursive2:1 else: fail("'rsource' with missing file did not raise exception") + # Test a tricky case involving symlinks. $srctree is tests/symlink, which + # points to tests/sub/sub, meaning tests/symlink/.. != tests/. Previously, + # using 'rsource' from a file sourced with an absolute path triggered an + # unsafe relpath() with tests/symlink/.. in it, crashing. + + os.environ["srctree"] = "Kconfiglib/tests/symlink" + os.environ["KCONFIG_SYMLINK_2"] = os.path.abspath( + "Kconfiglib/tests/sub/Kconfig_symlink_2") + if not os.path.isabs( + Kconfig("Kconfig_symlink_1").syms["FOUNDME"].nodes[0].filename): + + fail("Symlink + rsource issues") + print("Testing Kconfig.node_iter()") # Reuse tests/Klocation. The node_iter(unique_syms=True) case already gets # plenty of testing from write_config() as well. + os.environ["srctree"] = "Kconfiglib" c = Kconfig("tests/Klocation", warn=False) verify_equal( @@ -1169,9 +1183,6 @@ tests/Krecursive2:1 if not isinstance(node.item, Symbol)], ["choice", "menu", "comment"]) - # Get rid of custom 'srctree' from Klocation test - os.environ.pop("srctree", None) - print("Testing MenuNode.include_path") -- cgit v1.2.3