Skip to content

Commit 7e6bede

Browse files
committed
chore: Add more image validation
1 parent 92a9622 commit 7e6bede

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

rust/boil/src/build/bakefile.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ impl Bakefile {
391391
let image_name = image_name.replace('/', "__");
392392

393393
// The dots in the semantic version also need to be replaced.
394-
let image_version = image_version.to_string().replace('.', "_");
394+
let image_version = image_version.replace('.', "_");
395395

396396
format!("{image_name}-{image_version}")
397397
}

rust/boil/src/build/image.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,20 @@ use std::{
77
};
88

99
use serde::Deserialize;
10-
use snafu::{ResultExt as _, Snafu};
10+
use snafu::{ResultExt as _, Snafu, ensure};
1111

1212
use crate::{IfContext, build::docker::BuildArguments};
1313

1414
#[derive(Debug, Snafu)]
1515
pub enum ParseImageError {
1616
#[snafu(display("encountered invalid format, expected name[=version,...]"))]
1717
InvalidFormat,
18+
19+
#[snafu(display("the path contains unsupported characters: '.' or '~'"))]
20+
UnsupportedChars,
21+
22+
#[snafu(display("absolute paths are not supported"))]
23+
AbsolutePath,
1824
}
1925

2026
#[derive(Clone, Debug)]
@@ -29,11 +35,16 @@ impl FromStr for Image {
2935
fn from_str(s: &str) -> Result<Self, Self::Err> {
3036
let parts: Vec<_> = s.split('=').collect();
3137

38+
ensure!(!parts[0].contains(['.', '~']), UnsupportedCharsSnafu);
39+
ensure!(!parts[0].starts_with('/'), AbsolutePathSnafu);
40+
41+
let image_name = parts[0].trim_end_matches('/').to_owned();
42+
3243
match parts.len() {
33-
1 => Ok(Self::new_unversioned(parts[0].to_owned())),
44+
1 => Ok(Self::new_unversioned(image_name)),
3445
2 => {
3546
let versions: Vec<_> = parts[1].split(',').map(ToOwned::to_owned).collect();
36-
Ok(Self::new(parts[0].to_owned(), versions))
47+
Ok(Self::new(image_name, versions))
3748
}
3849
_ => InvalidFormatSnafu.fail(),
3950
}

rust/boil/src/cli.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ pub struct Cli {
1111
#[arg(short, long = "configuration", global = true, default_value_os_t = Self::default_config_path())]
1212
pub config_path: PathBuf,
1313

14-
#[arg(short, long, default_value_os_t = Self::default_base_path())]
15-
pub base_path: PathBuf,
16-
1714
#[command(subcommand)]
1815
pub command: Command,
1916
}
@@ -22,10 +19,6 @@ impl Cli {
2219
fn default_config_path() -> PathBuf {
2320
PathBuf::from("./boil.toml")
2421
}
25-
26-
fn default_base_path() -> PathBuf {
27-
PathBuf::from(".")
28-
}
2922
}
3023

3124
#[derive(Debug, Subcommand)]

0 commit comments

Comments
 (0)