vsock: don't panic if "connect PORT\n" is malformed

Instead of panic if the local peer doesn't send "connect PORT\n"
correctly, let's print an error, ignoring the command.

Print an error message also when allocating local port fails.

Reported-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
This commit is contained in:
Stefano Garzarella 2022-09-26 19:14:16 +02:00
parent d6775cd90d
commit 5986155c8a

View File

@ -208,12 +208,19 @@ impl VhostUserVsockThread {
let mut unix_stream = self.thread_backend.stream_map.remove(&fd).unwrap();
// Local peer is sending a "connect PORT\n" command
let peer_port = Self::read_local_stream_port(&mut unix_stream).unwrap();
let peer_port = match Self::read_local_stream_port(&mut unix_stream) {
Ok(port) => port,
Err(err) => {
warn!("Error while parsing \"connect PORT\n\" command: {:?}", err);
return;
}
};
// Allocate a local port number
let local_port = match self.allocate_local_port() {
Ok(lp) => lp,
Err(_) => {
Err(err) => {
warn!("Error while allocating local port: {:?}", err);
return;
}
};