Avoid NPE in get related changes

Do a null check before getting the change from change data.

A null pointer exception was reported when getting related changes [1].
The change that introduced this vulnerability is [2].

[1] https://groups.google.com/forum/#!topic/repo-discuss/3oS_ynJqGjo
[2] https://gerrit-review.googlesource.com/#/c/63221

Change-Id: I9ca2616492f665044e757a1c0d5dd604c29b21cc
This commit is contained in:
Janice Agustin 2015-06-29 12:41:35 -04:00 committed by David Pursehouse
parent 5115b49b02
commit 7bd1244b2c

View File

@ -116,7 +116,10 @@ public class GetRelated implements RestReadView<RevisionResource> {
PatchSet p = commits.get(c.name());
Change g = null;
if (p != null) {
g = changes.get(p.getId().getParentKey()).change();
ChangeData cd = changes.get(p.getId().getParentKey());
if (cd != null) {
g = cd.change();
}
added.add(p.getId().getParentKey());
}
parents.add(new ChangeAndCommit(g, p, c));