mirror of
https://github.com/chatmail/core.git
synced 2026-04-20 06:56:29 +03:00
Make dc_mimeparser::reconcat_mime() safe
This commit is contained in:
committed by
Floris Bruynooghe
parent
86eb9cc058
commit
edb0fa17af
@@ -843,11 +843,7 @@ unsafe fn mailmime_get_mime_type(
|
||||
}
|
||||
}
|
||||
*msg_type = Viewtype::File;
|
||||
reconcat_mime(
|
||||
raw_mime,
|
||||
b"text\x00" as *const u8 as *const libc::c_char,
|
||||
(*c).ct_subtype,
|
||||
);
|
||||
*raw_mime = reconcat_mime(Some("text"), as_opt_str((*c).ct_subtype)).strdup();
|
||||
return 110i32;
|
||||
}
|
||||
2 => {
|
||||
@@ -863,38 +859,22 @@ unsafe fn mailmime_get_mime_type(
|
||||
) == 0i32
|
||||
{
|
||||
*msg_type = Viewtype::File;
|
||||
reconcat_mime(
|
||||
raw_mime,
|
||||
b"image\x00" as *const u8 as *const libc::c_char,
|
||||
(*c).ct_subtype,
|
||||
);
|
||||
*raw_mime = reconcat_mime(Some("image"), as_opt_str((*c).ct_subtype)).strdup();
|
||||
return 110i32;
|
||||
} else {
|
||||
*msg_type = Viewtype::Image;
|
||||
}
|
||||
reconcat_mime(
|
||||
raw_mime,
|
||||
b"image\x00" as *const u8 as *const libc::c_char,
|
||||
(*c).ct_subtype,
|
||||
);
|
||||
*raw_mime = reconcat_mime(Some("image"), as_opt_str((*c).ct_subtype)).strdup();
|
||||
return 80i32;
|
||||
}
|
||||
3 => {
|
||||
*msg_type = Viewtype::Audio;
|
||||
reconcat_mime(
|
||||
raw_mime,
|
||||
b"audio\x00" as *const u8 as *const libc::c_char,
|
||||
(*c).ct_subtype,
|
||||
);
|
||||
*raw_mime = reconcat_mime(Some("audio"), as_opt_str((*c).ct_subtype)).strdup();
|
||||
return 90i32;
|
||||
}
|
||||
4 => {
|
||||
*msg_type = Viewtype::Video;
|
||||
reconcat_mime(
|
||||
raw_mime,
|
||||
b"video\x00" as *const u8 as *const libc::c_char,
|
||||
(*c).ct_subtype,
|
||||
);
|
||||
*raw_mime = reconcat_mime(Some("video"), as_opt_str((*c).ct_subtype)).strdup();
|
||||
return 100i32;
|
||||
}
|
||||
_ => {
|
||||
@@ -906,18 +886,14 @@ unsafe fn mailmime_get_mime_type(
|
||||
b"autocrypt-setup\x00" as *const u8 as *const libc::c_char,
|
||||
) == 0i32
|
||||
{
|
||||
reconcat_mime(
|
||||
raw_mime,
|
||||
b"application\x00" as *const u8 as *const libc::c_char,
|
||||
(*c).ct_subtype,
|
||||
);
|
||||
*raw_mime = reconcat_mime(None, as_opt_str((*c).ct_subtype)).strdup();
|
||||
return 111i32;
|
||||
}
|
||||
reconcat_mime(
|
||||
raw_mime,
|
||||
(*(*(*c).ct_type).tp_data.tp_discrete_type).dt_extension,
|
||||
(*c).ct_subtype,
|
||||
);
|
||||
*raw_mime = reconcat_mime(
|
||||
as_opt_str((*(*(*c).ct_type).tp_data.tp_discrete_type).dt_extension),
|
||||
as_opt_str((*c).ct_subtype),
|
||||
)
|
||||
.strdup();
|
||||
return 110i32;
|
||||
}
|
||||
},
|
||||
@@ -978,26 +954,11 @@ unsafe fn mailmime_get_mime_type(
|
||||
0
|
||||
}
|
||||
|
||||
unsafe fn reconcat_mime(
|
||||
raw_mime: *mut *mut libc::c_char,
|
||||
type_0: *const libc::c_char,
|
||||
subtype: *const libc::c_char,
|
||||
) {
|
||||
if !raw_mime.is_null() {
|
||||
*raw_mime = dc_mprintf(
|
||||
b"%s/%s\x00" as *const u8 as *const libc::c_char,
|
||||
if !type_0.is_null() {
|
||||
type_0
|
||||
} else {
|
||||
b"application\x00" as *const u8 as *const libc::c_char
|
||||
},
|
||||
if !subtype.is_null() {
|
||||
subtype
|
||||
} else {
|
||||
b"octet-stream\x00" as *const u8 as *const libc::c_char
|
||||
},
|
||||
)
|
||||
};
|
||||
fn reconcat_mime(type_0: Option<&str>, subtype: Option<&str>) -> String {
|
||||
let type_0 = type_0.unwrap_or("application");
|
||||
let subtype = subtype.unwrap_or("octet-stream");
|
||||
|
||||
format!("{}/{}", type_0, subtype)
|
||||
}
|
||||
|
||||
unsafe fn mailmime_is_attachment_disposition(mime: *mut mailmime) -> libc::c_int {
|
||||
|
||||
Reference in New Issue
Block a user