summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d542c72)
raw | patch | inline | side by side (parent: d542c72)
author | Junio C Hamano <gitster@pobox.com> | |
Thu, 20 Oct 2011 18:37:59 +0000 (11:37 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Thu, 20 Oct 2011 21:47:50 +0000 (14:47 -0700) |
... even beyond the first NUL in the buffer, when checking the commit
against the detached signature in the header.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
against the detached signature in the header.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
commit.c | patch | blob | history | |
t/t7510-signed-commit.sh | patch | blob | history |
diff --git a/commit.c b/commit.c
index 93045a2cdae33426182c544e92ba0330133a10d7..09693f78d92c2851c2edb9e627f99ee4e7bfbf57 100644 (file)
--- a/commit.c
+++ b/commit.c
unsigned long size;
enum object_type type;
char *buffer = read_sha1_file(sha1, &type, &size);
- int in_header, saw_signature = -1;
- char *line;
+ int saw_signature = -1;
+ char *line, *tail;
if (!buffer || type != OBJ_COMMIT)
goto cleanup;
line = buffer;
- in_header = 1;
+ tail = buffer + size;
saw_signature = 0;
- while (*line) {
- char *next = strchrnul(line, '\n');
- if (*next)
+ while (line < tail) {
+ char *next = memchr(line, '\n', tail - line);
+ if (!next)
+ next = tail;
+ else
next++;
- if (in_header && !prefixcmp(line, gpg_sig_header)) {
+ if (!prefixcmp(line, gpg_sig_header)) {
const char *sig = line + gpg_sig_header_len;
strbuf_add(signature, sig, next - sig);
saw_signature = 1;
} else {
+ if (*line == '\n')
+ /* dump the whole remainder of the buffer */
+ next = tail;
strbuf_add(payload, line, next - line);
}
- if (*line == '\n')
- in_header = 0;
line = next;
}
cleanup:
index 5c7475d818ee12157b98e88288dd5aad9b8be248..30401ced071c24aed5071442da1a9674bc7b7c7e 100755 (executable)
--- a/t/t7510-signed-commit.sh
+++ b/t/t7510-signed-commit.sh
test_expect_success GPG 'detect fudged signature' '
git cat-file commit master >raw &&
- sed -e "s/fourth signed/4th forged/" raw >forged &&
- git hash-object -w -t commit forged >forged.commit &&
- git show --pretty=short --show-signature $(cat forged.commit) >actual &&
- grep "BAD signature from" actual &&
- ! grep "Good signature from" actual
+
+ sed -e "s/fourth signed/4th forged/" raw >forged1 &&
+ git hash-object -w -t commit forged1 >forged1.commit &&
+ git show --pretty=short --show-signature $(cat forged1.commit) >actual1 &&
+ grep "BAD signature from" actual1 &&
+ ! grep "Good signature from" actual1
+'
+
+test_expect_success GPG 'detect fudged signature with NUL' '
+ git cat-file commit master >raw &&
+ cat raw >forged2 &&
+ echo Qwik | tr "Q" "\000" >>forged2 &&
+ git hash-object -w -t commit forged2 >forged2.commit &&
+ git show --pretty=short --show-signature $(cat forged2.commit) >actual2 &&
+ grep "BAD signature from" actual2 &&
+ ! grep "Good signature from" actual2
'
test_done