Null Check in UnknownField::AddAll() (#7328)

UnknownField::AddAll() is called (multiple times) from UnknownField::MergeFrom(). The `extras` parameter is one of: `varintList`, `fixed32List`, `fixed64List`, `lengthDelimitedList`, or `groupList`. All of these members can be null, and are appropriately checked in other usage. If attempting to parse a proto with unknown extensions, and exception is thrown (NRE).
This adds the appropriate null check inside UnknownField::AddAll().
pull/7835/head
CauhxMilloy 5 years ago committed by GitHub
parent 223e89157a
commit 090d28e8f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      csharp/src/Google.Protobuf/UnknownField.cs

@ -209,13 +209,13 @@ namespace Google.Protobuf
/// <summary>
/// Returns a new list containing all of the given specified values from
/// both the <paramref name="current"/> and <paramref name="extras"/> lists.
/// If <paramref name="current" /> is null and <paramref name="extras"/> is empty,
/// If <paramref name="current" /> is null and <paramref name="extras"/> is null or empty,
/// null is returned. Otherwise, either a new list is created (if <paramref name="current" />
/// is null) or the elements of <paramref name="extras"/> are added to <paramref name="current" />.
/// </summary>
private static List<T> AddAll<T>(List<T> current, IList<T> extras)
{
if (extras.Count == 0)
if (extras == null || extras.Count == 0)
{
return current;
}

Loading…
Cancel
Save