Skip to content

Commit 2c3aed1

Browse files
dturner-twgitster
authored andcommitted
pseudoref: check return values from read_ref()
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d96a539 commit 2c3aed1

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

refs.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2868,7 +2868,9 @@ static int write_pseudoref(const char *pseudoref, const unsigned char *sha1,
28682868

28692869
if (old_sha1) {
28702870
unsigned char actual_old_sha1[20];
2871-
read_ref(pseudoref, actual_old_sha1);
2871+
2872+
if (read_ref(pseudoref, actual_old_sha1))
2873+
die("could not read ref '%s'", pseudoref);
28722874
if (hashcmp(actual_old_sha1, old_sha1)) {
28732875
strbuf_addf(err, "Unexpected sha1 when writing %s", pseudoref);
28742876
rollback_lock_file(&lock);
@@ -2904,7 +2906,8 @@ static int delete_pseudoref(const char *pseudoref, const unsigned char *old_sha1
29042906
LOCK_DIE_ON_ERROR);
29052907
if (fd < 0)
29062908
die_errno(_("Could not open '%s' for writing"), filename);
2907-
read_ref(pseudoref, actual_old_sha1);
2909+
if (read_ref(pseudoref, actual_old_sha1))
2910+
die("could not read ref '%s'", pseudoref);
29082911
if (hashcmp(actual_old_sha1, old_sha1)) {
29092912
warning("Unexpected sha1 when deleting %s", pseudoref);
29102913
rollback_lock_file(&lock);

0 commit comments

Comments
 (0)