From 927cd571f8202f746c5986878733ad3f104805ca Mon Sep 17 00:00:00 2001 From: LoveSy Date: Tue, 19 Sep 2023 02:21:04 +0800 Subject: [PATCH] Fix `read_cert` crash when receive fd = -1 --- native/src/core/cert.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/native/src/core/cert.rs b/native/src/core/cert.rs index 57134a95b..b91a4d191 100644 --- a/native/src/core/cert.rs +++ b/native/src/core/cert.rs @@ -138,6 +138,9 @@ pub fn read_certificate(fd: RawFd, version: i32) -> Vec { Err(bad_apk!("cannot find certificate")) } + if fd == -1 { + return vec![]; + } let mut file = unsafe { File::from_raw_fd(fd) }; let r = inner(&mut file, version).log().unwrap_or(vec![]); std::mem::forget(file);