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

on Windows, strip the '\\?\' prefix from the canonical path #1471

Merged
merged 1 commit into from
Jul 9, 2020

Conversation

RalfJung
Copy link
Member

@RalfJung RalfJung commented Jul 9, 2020

This should help with rust-lang/rust#74146 (comment)

@RalfJung
Copy link
Member Author

RalfJung commented Jul 9, 2020

@bors r+

@bors
Copy link
Collaborator

bors commented Jul 9, 2020

📌 Commit 7d9d74e has been approved by RalfJung

@bors
Copy link
Collaborator

bors commented Jul 9, 2020

⌛ Testing commit 7d9d74e with merge b245786...

@bors
Copy link
Collaborator

bors commented Jul 9, 2020

☀️ Test successful - checks-travis, status-appveyor
Approved by: RalfJung
Pushing b245786 to master...

@bors bors merged commit b245786 into rust-lang:master Jul 9, 2020
@RalfJung RalfJung deleted the win branch July 9, 2020 07:28
let path = path.canonicalize().unwrap_or(path);

// On Windows, this produces a path starting with `\\?\`, which xargo cannot deal with.
// Strip that prefix; the resulting path should still be valid.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the path is more than 260 characters long, the \\?\ is required See the "Maximum Path Length Limitation" section of https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file

Copy link
Member Author

@RalfJung RalfJung Jul 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh man, Windows is hard to handle.^^
I think this should be a good enough hack to land the Miri fix in rustc now. It anyway only affetcs setups that set XARGO_RUST_SRC which should be rare.

Once Miri is green in rustc, we don't have to rush any more. Then I'll release a new xargo with japaric/xargo#297 and remove the hack here in Miri. @bjorn3 do you have a Windows system you could test this on?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I have switched to Linux a long time ago. Wine may help with testing though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drive by comment, but it seems to me that we only use canonicalize here to go from relative path to an absolute one. If that is the case, I suggest using std::env::current_dir().unwrap().join(val) as a better alternative. Note that join auto-magically handles abs path in a convenient way (= is susceptible to the directory traversal attack :0) )

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matklad that's a great idea, I like it. :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that std::env::current_dir().unwrap().join(val) is also incorrect on Windows, as drive relative paths are a thing (aka C:foo is relative to the current directory on that drive).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aka C:foo is relative to the current directory on that drive

I don't even know what that means, and I am not sure I want to.^^

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

Successfully merging this pull request may close these issues.

5 participants