summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org
diff options
context:
space:
mode:
authorThomas Wolf <thomas.wolf@paranor.ch>2019-04-21 21:23:30 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2019-06-07 16:19:31 +0200
commitd2600693bd5fb8bda20bae41467132668caa1e14 (patch)
tree64ad6dbc3092e53288eea0e9fcb73f289e0a5ea0 /org.eclipse.jgit/src/org
parent00f840dcd1fc53b3face0d824af0eb9de9d19f08 (diff)
downloadjgit-d2600693bd5fb8bda20bae41467132668caa1e14.tar.gz
jgit-d2600693bd5fb8bda20bae41467132668caa1e14.zip
Fix off-by-one error in RebaseTodoFile when reading a todo file
Commit messages of length 1 were not read. 'lineEnd' is the offset of the last character in the line before the terminating LF or CR-LF, and 'nextSpace' is actually the offset of the character _after_ the next space. With a one-character commit message, nextSpace == lineEnd. The code also assumes the commit message to be optional, but actually failed in that case because it read beyond the line ending. Fix that, too. Add a test case for reading a todo file. Bug: 546245 Change-Id: I368d63615930ea2398a6230e756442fd88870654 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.jgit/src/org')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/RebaseTodoFile.java12
1 files changed, 9 insertions, 3 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RebaseTodoFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RebaseTodoFile.java
index 06b4b227c8..c0fcd4161f 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RebaseTodoFile.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RebaseTodoFile.java
@@ -179,7 +179,7 @@ public class RebaseTodoFile {
int nextSpace = RawParseUtils.next(buf, tokenBegin, ' ');
int tokenCount = 0;
- while (tokenCount < 3 && nextSpace < lineEnd) {
+ while (tokenCount < 3 && nextSpace <= lineEnd) {
switch (tokenCount) {
case 0:
String actionToken = new String(buf, tokenBegin,
@@ -191,8 +191,14 @@ public class RebaseTodoFile {
break;
case 1:
nextSpace = RawParseUtils.next(buf, tokenBegin, ' ');
- String commitToken = new String(buf, tokenBegin,
- nextSpace - tokenBegin - 1, UTF_8);
+ String commitToken;
+ if (nextSpace > lineEnd + 1) {
+ commitToken = new String(buf, tokenBegin,
+ lineEnd - tokenBegin + 1, UTF_8);
+ } else {
+ commitToken = new String(buf, tokenBegin,
+ nextSpace - tokenBegin - 1, UTF_8);
+ }
tokenBegin = nextSpace;
commit = AbbreviatedObjectId.fromString(commitToken);
break;