mirror of
https://github.com/chatmail/core.git
synced 2026-04-23 08:26:30 +03:00
Check if input to dc_send_text_msg is valid utf8
With this change, passing invalid utf8 string to `dc_send_text_msg' does not crash application, it prints warning and returns error code. It should be admitted that this fix is sub-optimal: if input C string is valid utf8 (which is likely), result of successful conversion to `&str' is discarded in `dc_send_text_msg', and the same input C string is converted again with `as_str' in `prepare_msg_raw'. It is not clear how to fix it in non-disruptive way, since input C string is passed down to call stack as part of `dc_msg_t' struct, which is part of C ABI.
This commit is contained in:
@@ -976,6 +976,11 @@ pub unsafe fn dc_send_text_msg(
|
||||
return 0;
|
||||
}
|
||||
|
||||
if let Err(err) = as_str_safe(text_to_send) {
|
||||
warn!(context, 0, "{}", err);
|
||||
return 0;
|
||||
}
|
||||
|
||||
let mut msg = dc_msg_new(context, 10);
|
||||
(*msg).text = dc_strdup(text_to_send);
|
||||
let ret = dc_send_msg(context, chat_id, msg);
|
||||
|
||||
Reference in New Issue
Block a user