-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
std: sys: uefi: os: Implement join_paths #150993
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
base: main
Are you sure you want to change the base?
Conversation
|
rustbot has assigned @Mark-Simulacrum. Use |
723e209 to
e50d7bb
Compare
|
☔ The latest upstream changes (presumably #151107) made this pull request unmergeable. Please resolve the merge conflicts. |
e50d7bb to
988e7e2
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
988e7e2 to
0750de6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Only thought I have is that this is basically the same implementation as the Windows join_paths, so they could share code. But I don't see a good existing place to put that shared code, and it's not a large amount of duplicated code, so I don't feel strongly about avoiding the duplication.
library/std/src/sys/pal/uefi/os.rs
Outdated
| if v.contains(&(b'"' as u16)) { | ||
| return Err(JoinPathsError); | ||
| } else if v.contains(&PATHS_SEP) { | ||
| joined.push(b'"' as u16); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you point to documentation suggesting it's valid to quote elements of the PATH? I'm not seeing anything to that effect in the linked specification.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested on OVMF just now and indeed, while file names can contain ;, the path variable does not seem to support those paths. Using " does not seem to do anything (although it does not cause any error either).
So I have made ; an invalid character.
|
Reminder, once the PR becomes ready for a review, use |
0750de6 to
845f848
Compare
|
@rustbot ready |
845f848 to
85647ca
Compare
library/std/src/sys/pal/uefi/os.rs
Outdated
| joined.push(PATHS_SEP) | ||
| } | ||
| let v = path.encode_wide().collect::<Vec<u16>>(); | ||
| if v.contains("E) || v.contains(&PATHS_SEP) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think a path containing " is invalid (why do you think it is?) -- it just means that the file path has that character in it? The reason we need to forbid PATHS_SEP is that there's no way to escape that, so including it actually includes two paths (likely non-existent ones, though that's not guaranteed).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think a path containing
"is invalid (why do you think it is?) -- it just means that the file path has that character in it? The reason we need to forbid PATHS_SEP is that there's no way to escape that, so including it actually includes two paths (likely non-existent ones, though that's not guaranteed).
Well, according to UEFI shell spec, file name has the following rules: one or more ASCII characters, excluding * ? < > \ / ” : ). So from the perspective of path variable (which is specific to UEFI shell), a path cannot have ".
With that said, the reason of course is different.
;will give us an incorrect (i.e. something user might not have expected) path variable."will give us an invalid path.
So not sure if we need to throw error for " (and other invalid characters).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My sense is that it doesn't make sense to attempt to validate that the components are valid paths in join_paths, we should only validate that the paths are accurately joined (i.e., each path on input is present in the output or an error is returned).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I have removed the " check.
85647ca to
a7d25a7
Compare
library/std/src/sys/pal/uefi/os.rs
Outdated
| } | ||
|
|
||
| impl fmt::Display for JoinPathsError { | ||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| "not supported on this platform yet".fmt(f) | ||
| "path segment contains `\"` or `;`".fmt(f) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is stale.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
library/std/src/env.rs
Outdated
| @@ -518,8 +518,8 @@ pub struct JoinPathsError { | |||
| /// | |||
| /// Returns an [`Err`] (containing an error message) if one of the input | |||
| /// [`Path`]s contains an invalid character for constructing the `PATH` | |||
| /// variable (a double quote on Windows or a colon on Unix), or if the system | |||
| /// does not have a `PATH`-like variable (e.g. UEFI or WASI). | |||
| /// variable (a double quote on Windows or a colon on Unix and UEFI), or if | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's a semicolon on UEFI?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
a7d25a7 to
d7b193f
Compare
- PATHS_SEP is defined as global const since I will implement split_paths in the future. - Tested using OVMF using QEMU. Signed-off-by: Ayush Singh <ayush@beagleboard.org>
d7b193f to
3df2fa4
Compare
@rustbot label +O-UEFI