Skip to content

Commit

Permalink
Open file requests with trailing slash should fail
Browse files Browse the repository at this point in the history
When opening "file.txt/" explorer.exe expects to get
an error. This also fixes Run As Administrator, when
mimic is set to "ntfs".

Signed-off-by: Jorgen Lundman <lundman@lundman.net>
  • Loading branch information
lundman committed Oct 11, 2024
1 parent 740220f commit da1fdfb
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion module/os/windows/zfs/zfs_vnops_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ zfs_find_dvp_vp(zfsvfs_t *zfsvfs, char *filename, int finalpartmaynotexist,
int fullstrlen;
char namebuffer[MAXNAMELEN];
BOOLEAN FileOpenReparsePoint;
BOOLEAN has_trailing_separator = FALSE;

FileOpenReparsePoint =
BooleanFlagOn(options, FILE_OPEN_REPARSE_POINT);
Expand All @@ -624,8 +625,10 @@ zfs_find_dvp_vp(zfsvfs_t *zfsvfs, char *filename, int finalpartmaynotexist,
// Sometimes we are given a path like "\Directory\directory\"
// with the final separator, we want to eat that final character.
if ((fullstrlen > 2) &&
(filename[fullstrlen - 1] == '\\'))
(filename[fullstrlen - 1] == '\\')) {
filename[--fullstrlen] = 0;
has_trailing_separator = TRUE;
}

for (word = strtok_r(filename, "/\\", &brkt);
word;
Expand Down Expand Up @@ -756,6 +759,14 @@ zfs_find_dvp_vp(zfsvfs_t *zfsvfs, char *filename, int finalpartmaynotexist,
return (ESRCH);
}

// Check if we got a file, but request had trailing slash
if (vp != NULL && !vnode_isdir(vp) && has_trailing_separator) {
VN_RELE(vp);
VN_RELE(dvp);
// NTFS returns STATUS_OBJECT_NAME_INVALID
return (STATUS_OBJECT_NAME_INVALID); // ENOTDIR
}

if (lastname) {

*lastname = word /* ? word : filename */;
Expand Down Expand Up @@ -1773,6 +1784,7 @@ zfs_vnop_lookup_impl(PIRP Irp, PIO_STACK_LOCATION IrpSp, mount_t *zmo,
}
VN_RELE(dvp);
} else {

// Technically, this should call zfs_open() -
// but zfs_open is mostly empty

Expand Down

0 comments on commit da1fdfb

Please sign in to comment.