From f04bd35df972d28885f913a4276eee10a3f6f3cf Mon Sep 17 00:00:00 2001 From: roker Date: Tue, 6 Jul 2021 18:17:35 +0200 Subject: [PATCH 1/3] MIME-16: wrap the log output of possibly NULL strings. --- src/header_generator.cc | 2 +- src/pEpMIME_internal.hh | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/header_generator.cc b/src/header_generator.cc index 36c6fc9..9360975 100644 --- a/src/header_generator.cc +++ b/src/header_generator.cc @@ -89,7 +89,7 @@ namespace void generate(std::string& out, sv header_name, const pEp_identity* id) { - LOG << "GEN_ID: " << id->username << " | " << id->address << std::endl; + LOG << "GEN_ID: " << NN(id->username) << " | " << NN(id->address) << std::endl; static BasicRules br; out += exists(id->username) ? encode_header_if_necessary(br.phrase, header_name, id->username, qp::Word) + " " : std::string() ; diff --git a/src/pEpMIME_internal.hh b/src/pEpMIME_internal.hh index 1eb6f59..3670d33 100644 --- a/src/pEpMIME_internal.hh +++ b/src/pEpMIME_internal.hh @@ -37,6 +37,7 @@ #endif // C++17 switch +#define NN(str) ( (str) ? (str) : "(NULL)" ) #ifdef LOG_TO_STDERR #include From 4fbe5698778f67774f12557a0888b6f596e86855 Mon Sep 17 00:00:00 2001 From: roker Date: Tue, 6 Jul 2021 18:19:39 +0200 Subject: [PATCH 2/3] also remove U+007F in header values. --- src/headerparser.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/headerparser.cc b/src/headerparser.cc index 790d1ba..a70bdad 100644 --- a/src/headerparser.cc +++ b/src/headerparser.cc @@ -41,7 +41,7 @@ std::string robust_to_utf8(sv s) // NUL bytes confuse C code, especially the Engine. // MIME-15: remove all C0 control characters. - ret.erase( std::remove_if(ret.begin(), ret.end(), [](char c){ return uint8_t(c) < ' '; } ), ret.end() ); + ret.erase( std::remove_if(ret.begin(), ret.end(), [](char c){ return uint8_t(c) < ' ' || c=='\177'; } ), ret.end() ); return ret; } From c67b8c1105157415526833d1a372df9b065cd1f3 Mon Sep 17 00:00:00 2001 From: roker Date: Tue, 6 Jul 2021 18:46:21 +0200 Subject: [PATCH 3/3] MIME-16: albeit a blob with no mime_type is invalid, I shall not crash than. --- src/attachment.hh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/attachment.hh b/src/attachment.hh index e9d783e..04dcecc 100644 --- a/src/attachment.hh +++ b/src/attachment.hh @@ -19,7 +19,7 @@ namespace pEpMIME { explicit Attachment(const bloblist_t* b, unsigned nr_in_bloblist, bool has_pEp_msg_attachment) : data{b->size ? sv{b->value, b->size} : sv{}} - , mime_type{b->mime_type} + , mime_type{exists(b->mime_type) ? b->mime_type : "application/octet-stream"} , filename{exists(b->filename) ? b->filename : sv{}} , dtype{b->disposition} , need_te{need_transport_encoding(data)} @@ -37,7 +37,7 @@ namespace pEpMIME Attachment(sv _data, sv _mime_type) : data{_data} - , mime_type{_mime_type} + , mime_type{_mime_type.size() ? _mime_type : "application/octet-stream"} , filename{} , dtype{ PEP_CONTENT_DISP_OTHER } , need_te{ need_transport_encoding(data) }