This is an automated email from the git hooks/post-receive script. guillem pushed a commit to branch main in repository dpkg.
View the commit online: https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=f83207850fcbcfc8ea395f27cfb52d90546fb857 commit f83207850fcbcfc8ea395f27cfb52d90546fb857 Author: Guillem Jover <[email protected]> AuthorDate: Sun Aug 22 00:55:19 2021 +0200 libdpkg: Fix dpkg_fsys_get_path() to always strip leading / and ./ This function expects to prefix the pathname component with the filesystem root directory, which by default is represented as the empty string. When we pass to it an absolute pathname, we were ending up with duplicate slashes. Strip them before constructing the returned pathname. --- lib/dpkg/fsys-dir.c | 2 ++ lib/dpkg/t/t-fsys-dir.c | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/dpkg/fsys-dir.c b/lib/dpkg/fsys-dir.c index abffa6fa4..7e779d667 100644 --- a/lib/dpkg/fsys-dir.c +++ b/lib/dpkg/fsys-dir.c @@ -94,5 +94,7 @@ dpkg_fsys_get_dir(void) char * dpkg_fsys_get_path(const char *pathpart) { + pathpart = path_skip_slash_dotslash(pathpart); + return str_fmt("%s/%s", fsys_dir, pathpart); } diff --git a/lib/dpkg/t/t-fsys-dir.c b/lib/dpkg/t/t-fsys-dir.c index 721dab6ce..32f4aab2e 100644 --- a/lib/dpkg/t/t-fsys-dir.c +++ b/lib/dpkg/t/t-fsys-dir.c @@ -34,6 +34,10 @@ test_fsys_dir(void) test_str(dpkg_fsys_get_dir(), ==, ""); + newdir = dpkg_fsys_set_dir("/testdir//./"); + test_str(newdir, ==, "/testdir"); + test_str(dpkg_fsys_get_dir(), ==, "/testdir"); + newdir = dpkg_fsys_set_dir("/testdir"); test_str(newdir, ==, "/testdir"); test_str(dpkg_fsys_get_dir(), ==, "/testdir"); @@ -46,6 +50,14 @@ test_fsys_dir(void) test_str(dir, ==, "/testdir/testfile"); free(dir); + dir = dpkg_fsys_get_path("/testfile"); + test_str(dir, ==, "/testdir/testfile"); + free(dir); + + setenv("DPKG_ROOT", "/testenvdir//./", 1); + dpkg_fsys_set_dir(NULL); + test_str(dpkg_fsys_get_dir(), ==, "/testenvdir"); + setenv("DPKG_ROOT", "/testenvdir", 1); dpkg_fsys_set_dir(NULL); test_str(dpkg_fsys_get_dir(), ==, "/testenvdir"); @@ -54,6 +66,10 @@ test_fsys_dir(void) test_str(dir, ==, "/testenvdir/testfile"); free(dir); + dir = dpkg_fsys_get_path("/testfile"); + test_str(dir, ==, "/testenvdir/testfile"); + free(dir); + unsetenv("DPKG_ROOT"); dpkg_fsys_set_dir(NULL); test_str(dpkg_fsys_get_dir(), ==, ""); @@ -61,11 +77,15 @@ test_fsys_dir(void) dir = dpkg_fsys_get_path("testfile"); test_str(dir, ==, "/testfile"); free(dir); + + dir = dpkg_fsys_get_path("/testfile"); + test_str(dir, ==, "/testfile"); + free(dir); } TEST_ENTRY(test) { - test_plan(10); + test_plan(16); test_fsys_dir(); } -- Dpkg.Org's dpkg

