diff options
author | David Pursehouse <david.pursehouse@gmail.com> | 2018-12-20 15:51:08 +0900 |
---|---|---|
committer | David Pursehouse <david.pursehouse@gmail.com> | 2018-12-20 15:55:02 +0900 |
commit | 3e51a078d96263b0984332b3207caff07e52423d (patch) | |
tree | 9f45a4e6b9c95e1b1804a0b1c13d04f2630d6e6c | |
parent | 209b1e1cb33d37cab8e6147a50f7ec56b52b837d (diff) | |
parent | 3cb80a433df9d4d0a5eb8ac3d86f39dc9c8fc9d1 (diff) | |
download | jgit-3e51a078d96263b0984332b3207caff07e52423d.tar.gz jgit-3e51a078d96263b0984332b3207caff07e52423d.zip |
Merge branch 'stable-5.2'
* stable-5.2:
BasePackConnection: Check for expected length of ref advertisement
TransferConfig: Make constructors public
Update last JGit version
Change-Id: I4406d4f68136a2ce363701324b9a842ad468bc59
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
4 files changed, 38 insertions, 3 deletions
diff --git a/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties b/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties index af8d564983..fca9018db0 100644 --- a/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties +++ b/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties @@ -390,6 +390,7 @@ invalidPathPeriodAtEndWindows=Invalid path (period at end is ignored by Windows) invalidPathSpaceAtEndWindows=Invalid path (space at end is ignored by Windows): {0} invalidPathReservedOnWindows=Invalid path (''{0}'' is reserved on Windows): {1} invalidRedirectLocation=Invalid redirect location {0} -> {1} +invalidRefAdvertisementLine=Invalid ref advertisement line: ''{1}'' invalidReflogRevision=Invalid reflog revision: {0} invalidRefName=Invalid ref name: {0} invalidReftableBlock=Invalid reftable block diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java index 99445b2f48..a24cff1e49 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java @@ -451,6 +451,7 @@ public class JGitText extends TranslationBundle { /***/ public String invalidPathSpaceAtEndWindows; /***/ public String invalidPathReservedOnWindows; /***/ public String invalidRedirectLocation; + /***/ public String invalidRefAdvertisementLine; /***/ public String invalidReflogRevision; /***/ public String invalidRefName; /***/ public String invalidReftableBlock; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackConnection.java index 38eae1cd48..fcf78ac7b9 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackConnection.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackConnection.java @@ -57,6 +57,7 @@ import java.util.HashSet; import java.util.LinkedHashMap; import java.util.Set; +import org.eclipse.jgit.errors.InvalidObjectIdException; import org.eclipse.jgit.errors.NoRemoteRepositoryException; import org.eclipse.jgit.errors.PackProtocolException; import org.eclipse.jgit.errors.RemoteRepositoryException; @@ -222,6 +223,10 @@ abstract class BasePackConnection extends BaseConnection { } } + // Expecting to get a line in the form "sha1 refname" + if (line.length() < 41 || line.charAt(40) != ' ') { + throw invalidRefAdvertisementLine(line); + } String name = line.substring(41, line.length()); if (avail.isEmpty() && name.equals("capabilities^{}")) { //$NON-NLS-1$ // special line from git-receive-pack to show @@ -229,7 +234,12 @@ abstract class BasePackConnection extends BaseConnection { continue; } - final ObjectId id = ObjectId.fromString(line.substring(0, 40)); + final ObjectId id; + try { + id = ObjectId.fromString(line.substring(0, 40)); + } catch (InvalidObjectIdException e) { + throw invalidRefAdvertisementLine(line); + } if (name.equals(".have")) { //$NON-NLS-1$ additionalHaves.add(id); } else if (name.endsWith("^{}")) { //$NON-NLS-1$ @@ -318,6 +328,10 @@ abstract class BasePackConnection extends BaseConnection { return new PackProtocolException(uri, MessageFormat.format(JGitText.get().duplicateAdvertisementsOf, name)); } + private PackProtocolException invalidRefAdvertisementLine(String line) { + return new PackProtocolException(uri, MessageFormat.format(JGitText.get().invalidRefAdvertisementLine, line)); + } + /** {@inheritDoc} */ @Override public void close() { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java index 4f2ea64e16..d0db9f0e95 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java @@ -134,12 +134,31 @@ public class TransferConfig { final @Nullable ProtocolVersion protocolVersion; final String[] hideRefs; - TransferConfig(Repository db) { + /** + * Create a configuration honoring the repository's settings. + * + * @param db + * the repository to read settings from. The repository is not + * retained by the new configuration, instead its settings are + * copied during the constructor. + * @since 5.1.4 + */ + public TransferConfig(Repository db) { this(db.getConfig()); } + /** + * Create a configuration honoring settings in a + * {@link org.eclipse.jgit.lib.Config}. + * + * @param rc + * the source to read settings from. The source is not retained + * by the new configuration, instead its settings are copied + * during the constructor. + * @since 5.1.4 + */ @SuppressWarnings("nls") - TransferConfig(Config rc) { + public TransferConfig(Config rc) { boolean fsck = rc.getBoolean("transfer", "fsckobjects", false); fetchFsck = rc.getBoolean("fetch", "fsckobjects", fsck); receiveFsck = rc.getBoolean("receive", "fsckobjects", fsck); |