mailmime_get_mime_type: do not dereference null pointer

In C code there was a check for null pointer in reconcat_mime()
It did nothing if raw_mime was null.
Now the result is stored even when mailmime_get_mime_type is
explicitly called with null pointer.

This commit restores C core logic.

Fixes #420
This commit is contained in:
Alexander Krotov
2019-09-01 17:40:07 +03:00
parent c1a78d9c3e
commit 1ba7368c6d

View File

@@ -828,7 +828,9 @@ unsafe fn mailmime_get_mime_type(
} }
} }
*msg_type = Viewtype::File; *msg_type = Viewtype::File;
*raw_mime = reconcat_mime(Some("text"), as_opt_str((*c).ct_subtype)).strdup(); if !raw_mime.is_null() {
*raw_mime = reconcat_mime(Some("text"), as_opt_str((*c).ct_subtype)).strdup();
}
return 110i32; return 110i32;
} }
2 => { 2 => {
@@ -844,22 +846,31 @@ unsafe fn mailmime_get_mime_type(
) == 0i32 ) == 0i32
{ {
*msg_type = Viewtype::File; *msg_type = Viewtype::File;
*raw_mime = reconcat_mime(Some("image"), as_opt_str((*c).ct_subtype)).strdup(); if !raw_mime.is_null() {
*raw_mime =
reconcat_mime(Some("image"), as_opt_str((*c).ct_subtype)).strdup();
}
return 110i32; return 110i32;
} else { } else {
*msg_type = Viewtype::Image; *msg_type = Viewtype::Image;
} }
*raw_mime = reconcat_mime(Some("image"), as_opt_str((*c).ct_subtype)).strdup(); if !raw_mime.is_null() {
*raw_mime = reconcat_mime(Some("image"), as_opt_str((*c).ct_subtype)).strdup();
}
return 80i32; return 80i32;
} }
3 => { 3 => {
*msg_type = Viewtype::Audio; *msg_type = Viewtype::Audio;
*raw_mime = reconcat_mime(Some("audio"), as_opt_str((*c).ct_subtype)).strdup(); if !raw_mime.is_null() {
*raw_mime = reconcat_mime(Some("audio"), as_opt_str((*c).ct_subtype)).strdup();
}
return 90i32; return 90i32;
} }
4 => { 4 => {
*msg_type = Viewtype::Video; *msg_type = Viewtype::Video;
*raw_mime = reconcat_mime(Some("video"), as_opt_str((*c).ct_subtype)).strdup(); if !raw_mime.is_null() {
*raw_mime = reconcat_mime(Some("video"), as_opt_str((*c).ct_subtype)).strdup();
}
return 100i32; return 100i32;
} }
_ => { _ => {
@@ -871,14 +882,18 @@ 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
{ {
*raw_mime = reconcat_mime(None, as_opt_str((*c).ct_subtype)).strdup(); if !raw_mime.is_null() {
*raw_mime = reconcat_mime(None, as_opt_str((*c).ct_subtype)).strdup();
}
return 111i32; return 111i32;
} }
*raw_mime = reconcat_mime( if !raw_mime.is_null() {
as_opt_str((*(*(*c).ct_type).tp_data.tp_discrete_type).dt_extension), *raw_mime = reconcat_mime(
as_opt_str((*c).ct_subtype), as_opt_str((*(*(*c).ct_type).tp_data.tp_discrete_type).dt_extension),
) as_opt_str((*c).ct_subtype),
.strdup(); )
.strdup();
}
return 110i32; return 110i32;
} }
}, },