mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-25 06:52:13 +00:00
agent: Fix crasher if UpdateRoutes request empty
Check if the routes specified in the `UpdateRoutes` API is set before using it to avoid crashing the agent. Fixes: #949. Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
This commit is contained in:
parent
5615e5a7fe
commit
3d084c7d23
@ -954,6 +954,13 @@ impl protocols::agent_ttrpc::AgentService for agentService {
|
||||
req: protocols::agent::UpdateRoutesRequest,
|
||||
) -> ttrpc::Result<Routes> {
|
||||
let mut routes = protocols::agent::Routes::new();
|
||||
if req.routes.is_none() {
|
||||
return Err(ttrpc::Error::RpcStatus(ttrpc::get_status(
|
||||
ttrpc::Code::INVALID_ARGUMENT,
|
||||
format!("empty update routes request"),
|
||||
)));
|
||||
}
|
||||
|
||||
let rs = req.routes.clone().unwrap().Routes.into_vec();
|
||||
|
||||
let s = Arc::clone(&self.sandbox);
|
||||
@ -1839,4 +1846,21 @@ mod tests {
|
||||
|
||||
assert!(result.is_err(), "expected update interface to fail");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_update_routes() {
|
||||
let logger = slog::Logger::root(slog::Discard, o!());
|
||||
let sandbox = Sandbox::new(&logger).unwrap();
|
||||
|
||||
let agent_service = Box::new(agentService {
|
||||
sandbox: Arc::new(Mutex::new(sandbox)),
|
||||
});
|
||||
|
||||
let req = protocols::agent::UpdateRoutesRequest::default();
|
||||
let (ctx, _) = mk_ttrpc_context();
|
||||
|
||||
let result = agent_service.update_routes(&ctx, req);
|
||||
|
||||
assert!(result.is_err(), "expected update routes to fail");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user