wrealpath: Fail for file/something

This incorrectly allowed "file/something" if file existed (as a file), because it
checked "afile".

Fixes #5352.
This commit is contained in:
Fabian Homborg 2018-11-18 20:04:33 +01:00
parent b00b1af152
commit ca1c499069
3 changed files with 7 additions and 1 deletions

View File

@ -421,7 +421,9 @@ maybe_t<wcstring> wrealpath(const wcstring &pathname) {
} else {
errno = 0;
// Only call realpath() on the portion up to the last component.
narrow_res = realpath(narrow_path.substr(0, pathsep_idx).c_str(), tmpbuff);
// Be sure to include the last "/", so that the penultimate component is considered as a directory.
// Otherwise "file/something" succeeds.
narrow_res = realpath(narrow_path.substr(0, pathsep_idx + 1).c_str(), tmpbuff);
if (!narrow_res) return none();

View File

@ -1,2 +1,3 @@
builtin realpath: /this/better/be/an/invalid/path: No such file or directory
builtin realpath: .: No such file or directory
builtin realpath: realpath.out/..: Not a directory

View File

@ -80,4 +80,7 @@ else
echo "unexpected pwd-resolved-to-itself failure: $real_path != $PWD" >&2
end
# Confirm that the penultimate component still needs to be a directory:
builtin realpath realpath.out/..
exit 0