read_packed_refs(): die if packed-refs
contains bogus data
The old code ignored any lines that it didn't understand, including unterminated lines. This is dangerous. Instead, `die()` if the `packed-refs` file contains any unterminated lines or lines that we don't know how to handle. This fixes the tests added in the last commit. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
02a1a42056
commit
9308b7f3ca
@ -229,6 +229,9 @@ static struct packed_ref_cache *read_packed_refs(const char *packed_refs_file)
|
|||||||
const char *refname;
|
const char *refname;
|
||||||
const char *traits;
|
const char *traits;
|
||||||
|
|
||||||
|
if (!line.len || line.buf[line.len - 1] != '\n')
|
||||||
|
die("unterminated line in %s: %s", packed_refs_file, line.buf);
|
||||||
|
|
||||||
if (skip_prefix(line.buf, "# pack-refs with:", &traits)) {
|
if (skip_prefix(line.buf, "# pack-refs with:", &traits)) {
|
||||||
if (strstr(traits, " fully-peeled "))
|
if (strstr(traits, " fully-peeled "))
|
||||||
peeled = PEELED_FULLY;
|
peeled = PEELED_FULLY;
|
||||||
@ -253,9 +256,7 @@ static struct packed_ref_cache *read_packed_refs(const char *packed_refs_file)
|
|||||||
(peeled == PEELED_TAGS && starts_with(refname, "refs/tags/")))
|
(peeled == PEELED_TAGS && starts_with(refname, "refs/tags/")))
|
||||||
last->flag |= REF_KNOWS_PEELED;
|
last->flag |= REF_KNOWS_PEELED;
|
||||||
add_ref_entry(dir, last);
|
add_ref_entry(dir, last);
|
||||||
continue;
|
} else if (last &&
|
||||||
}
|
|
||||||
if (last &&
|
|
||||||
line.buf[0] == '^' &&
|
line.buf[0] == '^' &&
|
||||||
line.len == PEELED_LINE_LENGTH &&
|
line.len == PEELED_LINE_LENGTH &&
|
||||||
line.buf[PEELED_LINE_LENGTH - 1] == '\n' &&
|
line.buf[PEELED_LINE_LENGTH - 1] == '\n' &&
|
||||||
@ -267,6 +268,9 @@ static struct packed_ref_cache *read_packed_refs(const char *packed_refs_file)
|
|||||||
* reference:
|
* reference:
|
||||||
*/
|
*/
|
||||||
last->flag |= REF_KNOWS_PEELED;
|
last->flag |= REF_KNOWS_PEELED;
|
||||||
|
} else {
|
||||||
|
strbuf_setlen(&line, line.len - 1);
|
||||||
|
die("unexpected line in %s: %s", packed_refs_file, line.buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,7 +194,7 @@ test_expect_success 'notice d/f conflict with existing ref' '
|
|||||||
test_must_fail git branch foo/bar/baz/lots/of/extra/components
|
test_must_fail git branch foo/bar/baz/lots/of/extra/components
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_failure 'reject packed-refs with unterminated line' '
|
test_expect_success 'reject packed-refs with unterminated line' '
|
||||||
cp .git/packed-refs .git/packed-refs.bak &&
|
cp .git/packed-refs .git/packed-refs.bak &&
|
||||||
test_when_finished "mv .git/packed-refs.bak .git/packed-refs" &&
|
test_when_finished "mv .git/packed-refs.bak .git/packed-refs" &&
|
||||||
printf "%s" "$HEAD refs/zzzzz" >>.git/packed-refs &&
|
printf "%s" "$HEAD refs/zzzzz" >>.git/packed-refs &&
|
||||||
@ -203,7 +203,7 @@ test_expect_failure 'reject packed-refs with unterminated line' '
|
|||||||
test_cmp expected_err err
|
test_cmp expected_err err
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_failure 'reject packed-refs containing junk' '
|
test_expect_success 'reject packed-refs containing junk' '
|
||||||
cp .git/packed-refs .git/packed-refs.bak &&
|
cp .git/packed-refs .git/packed-refs.bak &&
|
||||||
test_when_finished "mv .git/packed-refs.bak .git/packed-refs" &&
|
test_when_finished "mv .git/packed-refs.bak .git/packed-refs" &&
|
||||||
printf "%s\n" "bogus content" >>.git/packed-refs &&
|
printf "%s\n" "bogus content" >>.git/packed-refs &&
|
||||||
@ -212,7 +212,7 @@ test_expect_failure 'reject packed-refs containing junk' '
|
|||||||
test_cmp expected_err err
|
test_cmp expected_err err
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_failure 'reject packed-refs with a short SHA-1' '
|
test_expect_success 'reject packed-refs with a short SHA-1' '
|
||||||
cp .git/packed-refs .git/packed-refs.bak &&
|
cp .git/packed-refs .git/packed-refs.bak &&
|
||||||
test_when_finished "mv .git/packed-refs.bak .git/packed-refs" &&
|
test_when_finished "mv .git/packed-refs.bak .git/packed-refs" &&
|
||||||
printf "%.7s %s\n" $HEAD refs/zzzzz >>.git/packed-refs &&
|
printf "%.7s %s\n" $HEAD refs/zzzzz >>.git/packed-refs &&
|
||||||
|
Loading…
Reference in New Issue
Block a user