mirror of
https://github.com/edera-dev/sprout.git
synced 2026-11-04 16:42:20 +00:00
fix(eficore): keep backslashes in command-line arguments
This commit is contained in:
1 parent
5be2c1b561
commit
4198dfbb8c
4 files changed
+39
-21
No files matched your search
Generated
-7
@@ -126,7 +126,6 @@ dependencies = [
|
|||||||
"anyhow",
|
"anyhow",
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"log",
|
"log",
|
||||||
"shlex",
|
|
||||||
"spin",
|
"spin",
|
||||||
"uefi",
|
"uefi",
|
||||||
"uefi-raw",
|
"uefi-raw",
|
||||||
@@ -339,12 +338,6 @@ dependencies = [
|
|||||||
"digest",
|
"digest",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "shlex"
|
|
||||||
version = "2.0.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "simd-adler32"
|
name = "simd-adler32"
|
||||||
version = "0.3.10"
|
version = "0.3.10"
|
||||||
|
|||||||
@@ -50,10 +50,6 @@ default-features = false
|
|||||||
version = "0.11.0"
|
version = "0.11.0"
|
||||||
default-features = false
|
default-features = false
|
||||||
|
|
||||||
[workspace.dependencies.shlex]
|
|
||||||
version = "2.0.1"
|
|
||||||
default-features = false
|
|
||||||
|
|
||||||
[workspace.dependencies.toml]
|
[workspace.dependencies.toml]
|
||||||
version = "1.1.6"
|
version = "1.1.6"
|
||||||
default-features = false
|
default-features = false
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ edition.workspace = true
|
|||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
bitflags.workspace = true
|
bitflags.workspace = true
|
||||||
log.workspace = true
|
log.workspace = true
|
||||||
shlex.workspace = true
|
|
||||||
spin.workspace = true
|
spin.workspace = true
|
||||||
uefi.workspace = true
|
uefi.workspace = true
|
||||||
uefi-raw.workspace = true
|
uefi-raw.workspace = true
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use alloc::string::{String, ToString};
|
use alloc::string::String;
|
||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use uefi::proto::loaded_image::LoadedImage;
|
use uefi::proto::loaded_image::LoadedImage;
|
||||||
@@ -33,14 +33,9 @@ pub fn args() -> Result<Vec<String>> {
|
|||||||
.collect::<Vec<u16>>();
|
.collect::<Vec<u16>>();
|
||||||
let options = String::from_utf16_lossy(&options);
|
let options = String::from_utf16_lossy(&options);
|
||||||
|
|
||||||
// Use shlex to parse the options.
|
// Split the options on whitespace, keeping quoted text together.
|
||||||
// If shlex fails, we will perform a simple whitespace split.
|
// Backslashes are kept as they are, since UEFI paths use them as separators.
|
||||||
let mut args = shlex::split(&options).unwrap_or_else(|| {
|
let mut args = split_options(&options);
|
||||||
options
|
|
||||||
.split_ascii_whitespace()
|
|
||||||
.map(|string| string.to_string())
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
});
|
|
||||||
|
|
||||||
// Correct firmware that may add invalid arguments at the start.
|
// Correct firmware that may add invalid arguments at the start.
|
||||||
// Witnessed this on a Dell Precision 5690 when direct booting.
|
// Witnessed this on a Dell Precision 5690 when direct booting.
|
||||||
@@ -66,3 +61,38 @@ pub fn args() -> Result<Vec<String>> {
|
|||||||
|
|
||||||
Ok(args)
|
Ok(args)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Splits `options` into arguments on whitespace. Text in single or double quotes is kept together.
|
||||||
|
fn split_options(options: &str) -> Vec<String> {
|
||||||
|
let mut args = Vec::new();
|
||||||
|
let mut current = String::new();
|
||||||
|
let mut in_arg = false;
|
||||||
|
let mut quote = None;
|
||||||
|
|
||||||
|
for c in options.chars() {
|
||||||
|
match quote {
|
||||||
|
Some(q) if c == q => quote = None,
|
||||||
|
Some(_) => current.push(c),
|
||||||
|
None if c == '"' || c == '\'' => {
|
||||||
|
quote = Some(c);
|
||||||
|
in_arg = true;
|
||||||
|
}
|
||||||
|
None if c.is_whitespace() => {
|
||||||
|
if in_arg {
|
||||||
|
args.push(core::mem::take(&mut current));
|
||||||
|
in_arg = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
current.push(c);
|
||||||
|
in_arg = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if in_arg {
|
||||||
|
args.push(current);
|
||||||
|
}
|
||||||
|
|
||||||
|
args
|
||||||
|
}
|
||||||
Reference in new issue
Block a user