Skip to content

Commit 22864d2

Browse files
committed
refactor: Ensure all components of a path a normal
1 parent a9be60f commit 22864d2

File tree

1 file changed

+7
-10
lines changed
  • rust/operator-binary/src/csi_server

1 file changed

+7
-10
lines changed

rust/operator-binary/src/csi_server/node.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ enum PublishError {
9898
path: PathBuf,
9999
},
100100

101-
#[snafu(display("file path {path:?} must not contain more than one component"))]
102-
InvalidComponentCount { path: PathBuf },
101+
#[snafu(display("file path {path:?} must only contain normal components"))]
102+
InvalidComponents { path: PathBuf },
103103

104104
#[snafu(display("file path {path:?} must not be absolute"))]
105105
InvalidAbsolutePath { path: PathBuf },
@@ -132,7 +132,7 @@ impl From<PublishError> for Status {
132132
PublishError::SetDirPermissions { .. } => Status::unavailable(full_msg),
133133
PublishError::CreateFile { .. } => Status::unavailable(full_msg),
134134
PublishError::WriteFile { .. } => Status::unavailable(full_msg),
135-
PublishError::InvalidComponentCount { .. } => Status::unavailable(full_msg),
135+
PublishError::InvalidComponents { .. } => Status::unavailable(full_msg),
136136
PublishError::InvalidAbsolutePath { .. } => Status::unavailable(full_msg),
137137
PublishError::TagPod { .. } => Status::unavailable(full_msg),
138138
PublishError::BuildAnnotation { .. } => Status::unavailable(full_msg),
@@ -257,16 +257,13 @@ impl SecretProvisionerNode {
257257
publish_error::InvalidAbsolutePathSnafu { path: &file_path }
258258
);
259259

260-
// Ensure that the file path only consists of a single normal
261-
// component. This prevents any path traversals up the path using
262-
// '..'.
260+
// Ensure that the file path only contains normal components. This
261+
// prevents any path traversals up the path using '..'.
263262
ensure!(
264263
file_path
265264
.components()
266-
.filter(|c| matches!(c, Component::Normal(_)))
267-
.count()
268-
== 1,
269-
publish_error::InvalidComponentCountSnafu { path: &file_path }
265+
.all(|c| matches!(c, Component::Normal(_))),
266+
publish_error::InvalidComponentsSnafu { path: &file_path }
270267
);
271268

272269
// Now, we can join the base and file path

0 commit comments

Comments
 (0)