From 0d3736d5c58f29ae55eeaf1db5f15f81db21b2f7 Mon Sep 17 00:00:00 2001 From: "fupan.lfp" Date: Thu, 7 Jan 2021 17:21:22 +0800 Subject: [PATCH] rustjail: fix the issue of sync read It should check the read count and return an error if read count didn't match the expected number. Fixes: #1233 Signed-off-by: fupan.lfp --- src/agent/rustjail/src/sync.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/agent/rustjail/src/sync.rs b/src/agent/rustjail/src/sync.rs index db2929f89f..aee0c4cad0 100644 --- a/src/agent/rustjail/src/sync.rs +++ b/src/agent/rustjail/src/sync.rs @@ -72,7 +72,15 @@ fn read_count(fd: RawFd, count: usize) -> Result> { } } - Ok(v[0..len].to_vec()) + if len != count { + Err(anyhow::anyhow!( + "invalid read count expect {} get {}", + count, + len + )) + } else { + Ok(v[0..len].to_vec()) + } } pub fn read_sync(fd: RawFd) -> Result> {