Bug 1401858 - add null check to avoid crash in EncodedHeader()/DecodedHeader(). r=mkmelin a=jorgk
authorJorg K <jorgk@jorgk.com>
Sun, 25 Nov 2018 23:28:26 +0100
changeset 33511 acbb511ca378e68243236d413f2040be83f7efac
parent 33510 54e10abf7960a7c7008c0f929e4ef4f1f730259a
child 33512 f31b3a9ea5a80493a2358ea7708f2f476d289608
push id387
push userclokep@gmail.com
push dateMon, 10 Dec 2018 21:30:47 +0000
reviewersmkmelin, jorgk
bugs1401858
Bug 1401858 - add null check to avoid crash in EncodedHeader()/DecodedHeader(). r=mkmelin a=jorgk
mailnews/mime/src/MimeHeaderParser.cpp
--- a/mailnews/mime/src/MimeHeaderParser.cpp
+++ b/mailnews/mime/src/MimeHeaderParser.cpp
@@ -70,16 +70,17 @@ void RemoveDuplicateAddresses(const nsAC
 
 nsCOMArray<msgIAddressObject> DecodedHeader(const nsAString &aHeader)
 {
   nsCOMArray<msgIAddressObject> retval;
   if (aHeader.IsEmpty()) {
     return retval;
   }
   nsCOMPtr<nsIMsgHeaderParser> headerParser(services::GetHeaderParser());
+  NS_ENSURE_TRUE(headerParser, retval);
   msgIAddressObject **addresses = nullptr;
   uint32_t length;
   nsresult rv = headerParser->ParseDecodedHeader(aHeader, false,
     &length, &addresses);
   MOZ_ASSERT(NS_SUCCEEDED(rv), "Javascript jsmime returned an error!");
   if (NS_SUCCEEDED(rv) && length > 0 && addresses) {
     retval.Adopt(addresses, length);
   }
@@ -89,16 +90,17 @@ nsCOMArray<msgIAddressObject> DecodedHea
 nsCOMArray<msgIAddressObject> EncodedHeader(const nsACString &aHeader,
                                             const char *aCharset)
 {
   nsCOMArray<msgIAddressObject> retval;
   if (aHeader.IsEmpty()) {
     return retval;
   }
   nsCOMPtr<nsIMsgHeaderParser> headerParser(services::GetHeaderParser());
+  NS_ENSURE_TRUE(headerParser, retval);
   msgIAddressObject **addresses = nullptr;
   uint32_t length;
   nsresult rv = headerParser->ParseEncodedHeader(aHeader, aCharset,
     false, &length, &addresses);
   MOZ_ASSERT(NS_SUCCEEDED(rv), "This should never fail!");
   if (NS_SUCCEEDED(rv) && length > 0 && addresses) {
     retval.Adopt(addresses, length);
   }