Browse Source

AIOOB in ChangeIdUtil.indexOfChangeId if amended message is a newline

Bug: 456792
Change-Id: Idf38a0db7dc72d672ff185dcac2f41f0012a6673
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
stable-3.7
Andrey Loskutov 10 years ago
parent
commit
428d31efd3
  1. 4
      org.eclipse.jgit.test/tst/org/eclipse/jgit/util/ChangeIdUtilTest.java
  2. 2
      org.eclipse.jgit/src/org/eclipse/jgit/util/ChangeIdUtil.java

4
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/ChangeIdUtilTest.java

@ -639,6 +639,10 @@ public class ChangeIdUtilTest {
@Test @Test
public void testIndexOfChangeId() { public void testIndexOfChangeId() {
assertEquals(-1, ChangeIdUtil.indexOfChangeId("", "\n"));
assertEquals(-1, ChangeIdUtil.indexOfChangeId("\n", "\n"));
assertEquals(-1, ChangeIdUtil.indexOfChangeId("\r\n", "\r\n"));
assertEquals(3, ChangeIdUtil.indexOfChangeId("x\n" + "\n" assertEquals(3, ChangeIdUtil.indexOfChangeId("x\n" + "\n"
+ "Change-Id: I3b7e4e16b503ce00f07ba6ad01d97a356dad7701\n", + "Change-Id: I3b7e4e16b503ce00f07ba6ad01d97a356dad7701\n",
"\n")); "\n"));

2
org.eclipse.jgit/src/org/eclipse/jgit/util/ChangeIdUtil.java

@ -229,6 +229,8 @@ public class ChangeIdUtil {
*/ */
public static int indexOfChangeId(String message, String delimiter) { public static int indexOfChangeId(String message, String delimiter) {
String[] lines = message.split(delimiter); String[] lines = message.split(delimiter);
if (lines.length == 0)
return -1;
int indexOfChangeIdLine = 0; int indexOfChangeIdLine = 0;
boolean inFooter = false; boolean inFooter = false;
for (int i = lines.length - 1; i >= 0; --i) { for (int i = lines.length - 1; i >= 0; --i) {

Loading…
Cancel
Save