Make dc_mimeparser::reconcat_mime() safe

This commit is contained in:
Dmitry Bogatov
2019-08-26 23:11:51 +00:00
committed by Floris Bruynooghe
parent 86eb9cc058
commit edb0fa17af

View File

@@ -843,11 +843,7 @@ unsafe fn mailmime_get_mime_type(
} }
} }
*msg_type = Viewtype::File; *msg_type = Viewtype::File;
reconcat_mime( *raw_mime = reconcat_mime(Some("text"), as_opt_str((*c).ct_subtype)).strdup();
raw_mime,
b"text\x00" as *const u8 as *const libc::c_char,
(*c).ct_subtype,
);
return 110i32; return 110i32;
} }
2 => { 2 => {
@@ -863,38 +859,22 @@ unsafe fn mailmime_get_mime_type(
) == 0i32 ) == 0i32
{ {
*msg_type = Viewtype::File; *msg_type = Viewtype::File;
reconcat_mime( *raw_mime = reconcat_mime(Some("image"), as_opt_str((*c).ct_subtype)).strdup();
raw_mime,
b"image\x00" as *const u8 as *const libc::c_char,
(*c).ct_subtype,
);
return 110i32; return 110i32;
} else { } else {
*msg_type = Viewtype::Image; *msg_type = Viewtype::Image;
} }
reconcat_mime( *raw_mime = reconcat_mime(Some("image"), as_opt_str((*c).ct_subtype)).strdup();
raw_mime,
b"image\x00" as *const u8 as *const libc::c_char,
(*c).ct_subtype,
);
return 80i32; return 80i32;
} }
3 => { 3 => {
*msg_type = Viewtype::Audio; *msg_type = Viewtype::Audio;
reconcat_mime( *raw_mime = reconcat_mime(Some("audio"), as_opt_str((*c).ct_subtype)).strdup();
raw_mime,
b"audio\x00" as *const u8 as *const libc::c_char,
(*c).ct_subtype,
);
return 90i32; return 90i32;
} }
4 => { 4 => {
*msg_type = Viewtype::Video; *msg_type = Viewtype::Video;
reconcat_mime( *raw_mime = reconcat_mime(Some("video"), as_opt_str((*c).ct_subtype)).strdup();
raw_mime,
b"video\x00" as *const u8 as *const libc::c_char,
(*c).ct_subtype,
);
return 100i32; return 100i32;
} }
_ => { _ => {
@@ -906,18 +886,14 @@ unsafe fn mailmime_get_mime_type(
b"autocrypt-setup\x00" as *const u8 as *const libc::c_char, b"autocrypt-setup\x00" as *const u8 as *const libc::c_char,
) == 0i32 ) == 0i32
{ {
reconcat_mime( *raw_mime = reconcat_mime(None, as_opt_str((*c).ct_subtype)).strdup();
raw_mime,
b"application\x00" as *const u8 as *const libc::c_char,
(*c).ct_subtype,
);
return 111i32; return 111i32;
} }
reconcat_mime( *raw_mime = reconcat_mime(
raw_mime, as_opt_str((*(*(*c).ct_type).tp_data.tp_discrete_type).dt_extension),
(*(*(*c).ct_type).tp_data.tp_discrete_type).dt_extension, as_opt_str((*c).ct_subtype),
(*c).ct_subtype, )
); .strdup();
return 110i32; return 110i32;
} }
}, },
@@ -978,26 +954,11 @@ unsafe fn mailmime_get_mime_type(
0 0
} }
unsafe fn reconcat_mime( fn reconcat_mime(type_0: Option<&str>, subtype: Option<&str>) -> String {
raw_mime: *mut *mut libc::c_char, let type_0 = type_0.unwrap_or("application");
type_0: *const libc::c_char, let subtype = subtype.unwrap_or("octet-stream");
subtype: *const libc::c_char,
) { format!("{}/{}", type_0, subtype)
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
},
)
};
} }
unsafe fn mailmime_is_attachment_disposition(mime: *mut mailmime) -> libc::c_int { unsafe fn mailmime_is_attachment_disposition(mime: *mut mailmime) -> libc::c_int {