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 31947 879f355b920c29492bf3867c7406df174d26f08b
parent 31946 e3a599bf7d540a475f30b807ed6711bce1f16cfb
child 31948 949fc4394c9f2a940139ed16aa214c9d5337e6b6
push id108
push usermozilla@jorgk.com
push dateMon, 26 Nov 2018 22:20:21 +0000
treeherdercomm-esr60@607e71389128 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
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
@@ -71,16 +71,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);
   }
@@ -90,16 +91,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);
   }