From 46f4205fffc3fb090de466e5e7ddfd04ae8d13c6 Mon Sep 17 00:00:00 2001 From: Sergey Bobrenok Date: Sun, 24 Apr 2022 16:33:33 +0300 Subject: [PATCH] Avoid zero-length prefixes in PATH A zero-length prefix in PATH is a legacy feature that indicates the current working directory. https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_03 Found in ru.nsu.bobrofon.easysshfs, see: https://gitlab.com/fdroid/fdroiddata/-/merge_requests/10953#note_921802636 --- fdroidserver/common.py | 2 +- tests/common.TestCase | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/fdroidserver/common.py b/fdroidserver/common.py index 2658d4a4..403bb74d 100644 --- a/fdroidserver/common.py +++ b/fdroidserver/common.py @@ -3006,7 +3006,7 @@ def set_FDroidPopen_env(build=None): if build is not None: path = build.ndk_path() paths = orig_path.split(os.pathsep) - if path not in paths: + if path and path not in paths: paths = [path] + paths env['PATH'] = os.pathsep.join(paths) for n in ['ANDROID_NDK', 'NDK', 'ANDROID_NDK_HOME']: diff --git a/tests/common.TestCase b/tests/common.TestCase index be2a04bd..a29920be 100755 --- a/tests/common.TestCase +++ b/tests/common.TestCase @@ -2364,6 +2364,14 @@ class CommonTest(unittest.TestCase): "%s_%s.exe" % (app.id, build.versionCode), ) + def test_no_zero_length_ndk_path_prefixes(self): + fdroidserver.common.config = {'ndk_paths': {}} + build = fdroidserver.metadata.Build() + + os.environ['PATH'] = '/usr/bin:/usr/sbin' + fdroidserver.common.set_FDroidPopen_env(build) + self.assertNotIn('', os.getenv('PATH').split(os.pathsep)) + if __name__ == "__main__": os.chdir(os.path.dirname(__file__))