From c503118d16161bce165ac6a69e73844e0d811259 Mon Sep 17 00:00:00 2001 From: Qiu Wenbo Date: Fri, 20 Mar 2020 11:50:39 +0800 Subject: [PATCH] vmm: fix a corrupted stack caused by get_win_size According to `asm-generic/termios.h`, the `struct winsize` should be: struct winsize { unsigned short ws_row; unsigned short ws_col; unsigned short ws_xpixel; unsigned short ws_ypixel; }; The ioctl of TIOCGWINSZ will trigger a segfault on aarch64. Signed-off-by: Qiu Wenbo --- vmm/src/device_manager.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index 9f2ae09e1..649b76df1 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -265,14 +265,15 @@ type VirtioDeviceArc = Arc>; pub fn get_win_size() -> (u16, u16) { #[repr(C)] + #[derive(Default)] struct WS { rows: u16, cols: u16, + xpixel: u16, + ypixel: u16, }; - let ws: WS = WS { - rows: 0u16, - cols: 0u16, - }; + let ws: WS = WS::default(); + unsafe { libc::ioctl(0, TIOCGWINSZ, &ws); }