better handle of null pointer

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2023-05-16 17:17:20 +08:00
parent 31b96a44de
commit 607f2d5d9d
2 changed files with 10 additions and 1 deletions

View File

@ -312,6 +312,15 @@ fn request_plugin_sign(id: String, msg_to_rustdesk: MsgToRustDesk) -> PluginRetu
) {
Ok(ret) => {
debug_assert!(!ret.msg.is_null(), "msg is null");
if ret.msg.is_null() {
// unreachable
log::error!(
"The returned message pointer of plugin status is null, plugin id: '{}', code: {}",
id,
ret.code,
);
return PluginReturn::success();
}
let msg = cstr_to_string(ret.msg).unwrap_or_default();
free_c_ptr(ret.msg as _);
if ret.code == super::errno::ERR_SUCCESS {

View File

@ -81,7 +81,7 @@ impl PluginReturn {
(self.code, "".to_owned())
} else {
if self.msg.is_null() {
log::warn!("The message pointer is null");
log::warn!("The message pointer from the plugin is null, but the error code is {}", self.code);
return (self.code, "".to_owned())
}
let msg = cstr_to_string(self.msg).unwrap_or_default();