diff options
author | Jeff King <peff@peff.net> | 2013-02-20 14:53:33 -0500 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2013-02-20 13:42:20 -0800 |
commit | b7b021701cea6c9e54c826e1f6bc5faa9d3fef53 (patch) | |
tree | a6a33c5bae59bcdab2a9ea1642619beb3b5b5c36 /upload-pack.c | |
parent | 004825d314db4ba3f34ef499e3522ef72792d896 (diff) | |
download | git-b7b021701cea6c9e54c826e1f6bc5faa9d3fef53.tar.gz git-b7b021701cea6c9e54c826e1f6bc5faa9d3fef53.tar.xz |
upload-pack: use get_sha1_hex to parse "shallow" lines
When we receive a line like "shallow <sha1>" from the
client, we feed the <sha1> part to get_sha1. This is a
mistake, as the argument on a shallow line is defined by
Documentation/technical/pack-protocol.txt to contain an
"obj-id". This is never defined in the BNF, but it is clear
from the text and from the other uses that it is meant to be
a hex sha1, not an arbitrary identifier (and that is what
fetch-pack has always sent).
We should be using get_sha1_hex instead, which doesn't allow
the client to request arbitrary junk like "HEAD@{yesterday}".
Because this is just marking shallow objects, the client
couldn't actually do anything interesting (like fetching
objects from unreachable reflog entries), but we should keep
our parsing tight to be on the safe side.
Because get_sha1 is for the most part a superset of
get_sha1_hex, in theory the only behavior change should be
disallowing non-hex object references. However, there is
one interesting exception: get_sha1 will only parse
a 40-character hex sha1 if the string has exactly 40
characters, whereas get_sha1_hex will just eat the first 40
characters, leaving the rest. That means that current
versions of git-upload-pack will not accept a "shallow"
packet that has a trailing newline, even though the protocol
documentation is clear that newlines are allowed (even
encouraged) in non-binary parts of the protocol.
This never mattered in practice, though, because fetch-pack,
contrary to the protocol documentation, does not include a
newline in its shallow lines. JGit follows its lead (though
it correctly is strict on the parsing end about wanting a
hex object id).
We do not adjust fetch-pack to send newlines here, as it
would break communication with older versions of git (and
there is no actual benefit to doing so, except for
consistency with other parts of the protocol).
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'upload-pack.c')
-rw-r--r-- | upload-pack.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/upload-pack.c b/upload-pack.c index 30146a04f..b058e8de5 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -596,7 +596,7 @@ static void receive_needs(void) if (!prefixcmp(line, "shallow ")) { unsigned char sha1[20]; struct object *object; - if (get_sha1(line + 8, sha1)) + if (get_sha1_hex(line + 8, sha1)) die("invalid shallow line: %s", line); object = parse_object(sha1); if (!object) |