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

'.' and '..' components in relative paths in std.os.windows.OpenFile #6044

Closed
kubkon opened this issue Aug 13, 2020 · 3 comments · Fixed by #7664
Closed

'.' and '..' components in relative paths in std.os.windows.OpenFile #6044

kubkon opened this issue Aug 13, 2020 · 3 comments · Fixed by #7664
Labels
os-windows standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@kubkon
Copy link
Member

kubkon commented Aug 13, 2020

While working on #5701 and #5993 I've noticed that doing something like this on Windows:

const fd: fd_t = some_fd_thats_non_null;
const pathname = [_]u16{ '.' }; // or '..', or in fact, having '.' or '..' anywhere in the path
const new_fd = try std.os.windows.OpenFile(pathname, .{ .dir = fd });
defer std.os.windows.CloseHandle(new_fd);

will yield a runtime panic (actually, NtCreateFile will trip on OBJECT_NAME_INVALID). As far as I can work out, this is due to the presence of '.' and '..' in the pathname argument. My question is here, is there any simple way around this, or are we forced to re-implement CreateFileW where we either query the OS for the handle to cwd, or we use the .dir handle, get the canonical path to it using GetFinalPathNameByHandle, concatenate the resultant path with the specified argument path, and feed this path into NtCreateFile again (not sure if that would even work since I'd imagine we'd prepend \??\ to the resultant path which could potentially not accept '.' and '..' as valid path components)?

I'm not yet convinced whether we'd want to enable this kind of behaviour for all calls using std.os.windows.OpenFile, however, it does seem useful for std.os.realpath and std.fs.Dir.realpath, when canonicalizing the pathnames.

@kubkon kubkon added question No questions on the issue tracker, please. standard library This issue involves writing Zig code for the standard library. os-windows labels Aug 13, 2020
@Vexu Vexu added this to the 0.7.0 milestone Aug 13, 2020
@squeek502
Copy link
Collaborator

Related: #4659

@kubkon
Copy link
Member Author

kubkon commented Aug 13, 2020

Related: #4659

Nice, thanks @squeek502!

@andrewrk andrewrk removed the question No questions on the issue tracker, please. label Oct 17, 2020
@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Oct 17, 2020
@marler8997
Copy link
Contributor

marler8997 commented Oct 19, 2020

Here's an easy way to reproduce this:

The compiler fails with error: Unexpected when a source file has .. on Windows:

> mkdir src
> echo "" > src\bug.zig
> zig build-obj src\..\src\bug.zig
error: Unexpected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
os-windows standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants