Skip to content

Commit 5583fe3

Browse files
ppennaCopilot
andcommitted
cli: check a managed exec request apart from its exchange
Session::exec checked a workload's arguments, working directory, and environment, and encoded its request, once it had attached to the VM. Those checks and the encoding move to Session::exec_payload, which exec still calls first, so that a caller can refuse a request that exec would refuse before it starts a VM. exec keeps the check of its response timeout, which concerns the exchange alone. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 09a64b6 commit 5583fe3

1 file changed

Lines changed: 22 additions & 14 deletions

File tree

‎nvx-rs/src/host/cli/session.rs‎

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -610,19 +610,11 @@ impl Session {
610610
Ok(())
611611
}
612612

613-
/// Runs a workload and returns how it ended, as `ControlSession.exec` does: the request and
614-
/// every response must arrive within `response_timeout` seconds of each other's start.
615-
pub(crate) fn exec(
616-
&mut self,
617-
request: &ExecRequest,
618-
response_timeout: f64,
619-
) -> Result<ExecResult> {
613+
/// Checks the workload of `request` and returns the payload of its exec request, as
614+
/// [`exec`](Self::exec) sends it, so that a caller can refuse a request before it starts a
615+
/// VM.
616+
pub(crate) fn exec_payload(request: &ExecRequest) -> Result<Vec<u8>> {
620617
let refused = |message: &str| Exit::error(ErrorCode::Unsupported, message);
621-
if !(response_timeout > 0.0 && response_timeout < f64::INFINITY) {
622-
return Err(refused(
623-
"managed exec response timeout must be positive and finite",
624-
));
625-
}
626618
let arguments = &request.arguments;
627619
if !(1..=MAX_ARGUMENTS).contains(&arguments.len()) {
628620
return Err(refused("managed exec requires 1 through 64 arguments"));
@@ -665,8 +657,24 @@ impl Session {
665657
environment,
666658
};
667659
// The checks above leave only the size of the request for the encoder to refuse.
668-
let payload = encode_exec_payload(&workload)
669-
.map_err(|_| refused("managed exec request exceeds the protocol limit"))?;
660+
encode_exec_payload(&workload)
661+
.map_err(|_| refused("managed exec request exceeds the protocol limit"))
662+
}
663+
664+
/// Runs a workload and returns how it ended, as `ControlSession.exec` does: the request and
665+
/// every response must arrive within `response_timeout` seconds of each other's start.
666+
pub(crate) fn exec(
667+
&mut self,
668+
request: &ExecRequest,
669+
response_timeout: f64,
670+
) -> Result<ExecResult> {
671+
if !(response_timeout > 0.0 && response_timeout < f64::INFINITY) {
672+
return Err(Exit::error(
673+
ErrorCode::Unsupported,
674+
"managed exec response timeout must be positive and finite",
675+
));
676+
}
677+
let payload = Self::exec_payload(request)?;
670678
let request_id = request_id()?;
671679
let deadline = Deadline::after(response_timeout);
672680
self.send(APP_EXEC, request_id, &payload, deadline)?;

0 commit comments

Comments
 (0)