Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect path resolving for concatenated path separators. #38

Closed
kuepe-sl opened this issue Dec 1, 2021 · 1 comment
Closed

Incorrect path resolving for concatenated path separators. #38

kuepe-sl opened this issue Dec 1, 2021 · 1 comment

Comments

@kuepe-sl
Copy link

kuepe-sl commented Dec 1, 2021

FilePath::resolved() goes wrong when you have multiple concatenated path separators, combined with path traversal paths.

a/b//../c should be resolved to a/c. cppfs instead resolves it to a/b/c

Windows 10 and Ubuntu 20.04 both treat concatenated path separators as "one" path separator.
a/b//c////../../d is treated as a/b/c/../../d and thus is resolved to a/d.

Here is a small program to illustrate the behaviour:

#include <string>
#include <iostream>
#include <cppfs/FilePath.h>

int main(int argc, char* argv[])
{
    std::string p1 = "/usr/bin/bash";
    std::string p2 = "/usr/bin/../bin/bash";
    std::string p3 = "/usr/bin//../bin/bash";
    std::cout << "p1: " << p1 << " -> FilePath::resolved: " << cppfs::FilePath{p1}.resolved() << "\n";
    std::cout << "p2: " << p2 << " -> FilePath::resolved: " << cppfs::FilePath{p2}.resolved() << "\n";
    std::cout << "p3: " << p3 << " -> FilePath::resolved: " << cppfs::FilePath{p3}.resolved() << "\n";
    return 0;
}

Building the program against the current cppfs master results in the following output:

p1: /usr/bin/bash -> FilePath::resolved: /usr/bin/bash
p2: /usr/bin/../bin/bash -> FilePath::resolved: /usr/bin/bash
p3: /usr/bin//../bin/bash -> FilePath::resolved: /usr/bin/bin/bash

I then gave all of the paths to file:

$ file /usr/bin/bash /usr/bin/../bin/bash /usr/bin//../bin/bash /usr/bin/bin/bash
/usr/bin/bash:         ELF 64-bit LSB shared object, [...]
/usr/bin/../bin/bash:  ELF 64-bit LSB shared object, [...]
/usr/bin//../bin/bash: ELF 64-bit LSB shared object, [...]
/usr/bin/bin/bash: cannot open `/usr/bin/bin/bash' (No such file or directory)

As seen, the last path (p3 resolved by cppfs) results in a "file not found" when it should not.

@scheibel
Copy link
Member

Thanks for reporting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants