Skip to content

Commit

Permalink
pseudoref: check return values from read_ref()
Browse files Browse the repository at this point in the history
These codepaths attempt to compare the "expected" current value with
the actual current value, but did not check if we successfully read
the current value before comparison.

Signed-off-by: David Turner <dturner@twopensource.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
David Turner authored and Junio C Hamano committed Aug 11, 2015
1 parent d96a539 commit 2c3aed1
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2868,7 +2868,9 @@ static int write_pseudoref(const char *pseudoref, const unsigned char *sha1,

if (old_sha1) {
unsigned char actual_old_sha1[20];
read_ref(pseudoref, actual_old_sha1);

if (read_ref(pseudoref, actual_old_sha1))
die("could not read ref '%s'", pseudoref);
if (hashcmp(actual_old_sha1, old_sha1)) {
strbuf_addf(err, "Unexpected sha1 when writing %s", pseudoref);
rollback_lock_file(&lock);
Expand Down Expand Up @@ -2904,7 +2906,8 @@ static int delete_pseudoref(const char *pseudoref, const unsigned char *old_sha1
LOCK_DIE_ON_ERROR);
if (fd < 0)
die_errno(_("Could not open '%s' for writing"), filename);
read_ref(pseudoref, actual_old_sha1);
if (read_ref(pseudoref, actual_old_sha1))
die("could not read ref '%s'", pseudoref);
if (hashcmp(actual_old_sha1, old_sha1)) {
warning("Unexpected sha1 when deleting %s", pseudoref);
rollback_lock_file(&lock);
Expand Down

0 comments on commit 2c3aed1

Please sign in to comment.