mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-05-01 13:14:33 +00:00
agent: Fix crasher if UpdateInterface request empty
Check if the interface specified in the `UpdateInterface` API is set before using it to avoid crashing the agent. Fixes: #950. Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
This commit is contained in:
parent
71be16c401
commit
5615e5a7fe
@ -919,6 +919,13 @@ impl protocols::agent_ttrpc::AgentService for agentService {
|
|||||||
_ctx: &ttrpc::TtrpcContext,
|
_ctx: &ttrpc::TtrpcContext,
|
||||||
req: protocols::agent::UpdateInterfaceRequest,
|
req: protocols::agent::UpdateInterfaceRequest,
|
||||||
) -> ttrpc::Result<Interface> {
|
) -> ttrpc::Result<Interface> {
|
||||||
|
if req.interface.is_none() {
|
||||||
|
return Err(ttrpc::Error::RpcStatus(ttrpc::get_status(
|
||||||
|
ttrpc::Code::INVALID_ARGUMENT,
|
||||||
|
format!("empty update interface request"),
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
let interface = req.interface.clone();
|
let interface = req.interface.clone();
|
||||||
let s = Arc::clone(&self.sandbox);
|
let s = Arc::clone(&self.sandbox);
|
||||||
let mut sandbox = s.lock().unwrap();
|
let mut sandbox = s.lock().unwrap();
|
||||||
@ -1755,7 +1762,27 @@ fn load_kernel_module(module: &protocols::agent::KernelModule) -> Result<()> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::protocols::agent_ttrpc::AgentService;
|
||||||
use oci::{Hook, Hooks};
|
use oci::{Hook, Hooks};
|
||||||
|
use std::sync::mpsc::{Receiver, Sender};
|
||||||
|
use ttrpc::{MessageHeader, TtrpcContext};
|
||||||
|
|
||||||
|
fn mk_ttrpc_context() -> (TtrpcContext, Receiver<(MessageHeader, Vec<u8>)>) {
|
||||||
|
let mh = MessageHeader::default();
|
||||||
|
|
||||||
|
let (tx, rx): (
|
||||||
|
Sender<(MessageHeader, Vec<u8>)>,
|
||||||
|
Receiver<(MessageHeader, Vec<u8>)>,
|
||||||
|
) = channel();
|
||||||
|
|
||||||
|
let ctx = TtrpcContext {
|
||||||
|
fd: -1,
|
||||||
|
mh: mh,
|
||||||
|
res_tx: tx,
|
||||||
|
};
|
||||||
|
|
||||||
|
(ctx, rx)
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_load_kernel_module() {
|
fn test_load_kernel_module() {
|
||||||
@ -1795,4 +1822,21 @@ mod tests {
|
|||||||
append_guest_hooks(&s, &mut oci);
|
append_guest_hooks(&s, &mut oci);
|
||||||
assert_eq!(s.hooks, oci.hooks);
|
assert_eq!(s.hooks, oci.hooks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_update_interface() {
|
||||||
|
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::UpdateInterfaceRequest::default();
|
||||||
|
let (ctx, _) = mk_ttrpc_context();
|
||||||
|
|
||||||
|
let result = agent_service.update_interface(&ctx, req);
|
||||||
|
|
||||||
|
assert!(result.is_err(), "expected update interface to fail");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user