Skip to content

Commit

Permalink
Add more bounds checking for TryParseMailbox()
Browse files Browse the repository at this point in the history
Fixes issue #421
  • Loading branch information
jstedfast committed Jul 26, 2018
1 parent efa8508 commit 4044269
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions MimeKit/InternetAddress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -425,16 +425,16 @@ internal static bool TryParseMailbox (ParserOptions options, byte[] text, int st
} while (index < endIndex && text[index] == '<');
}

if (index < endIndex && !ParseUtils.SkipCommentsAndWhiteSpace (text, ref index, endIndex, throwOnError))
return false;

if (index >= endIndex) {
if (throwOnError)
throw new ParseException (string.Format ("Incomplete mailbox at offset {0}", startIndex), startIndex, index);

return false;
}

if (!ParseUtils.SkipCommentsAndWhiteSpace (text, ref index, endIndex, throwOnError))
return false;

if (text[index] == (byte) '@') {
// Note: we always pass 'false' as the throwOnError argument here so that we can throw a more informative exception on error
if (!DomainList.TryParse (text, ref index, endIndex, false, out route)) {
Expand All @@ -451,10 +451,18 @@ internal static bool TryParseMailbox (ParserOptions options, byte[] text, int st
return false;
}

// skip over ':'
index++;

if (!ParseUtils.SkipCommentsAndWhiteSpace (text, ref index, endIndex, throwOnError))
return false;

if (index >= endIndex) {
if (throwOnError)
throw new ParseException (string.Format ("Incomplete mailbox at offset {0}", startIndex), startIndex, index);

return false;
}
}

// Note: The only syntactically correct sentinel token here is the '>', but alas... to deal with the first example
Expand Down

0 comments on commit 4044269

Please sign in to comment.