Skip to content

Commit 6ee1821

Browse files
bk2204gitster
authored andcommitted
refs: prevent accidental NULL dereference in write_pseudoref
Several of the refs functions take NULL to indicate that the ref is not to be updated. If refs_update_ref were called with a NULL new object ID, we could pass that NULL pointer to write_pseudoref, which would then segfault when it dereferenced it. Instead, simply return successfully, since if we don't want to update the pseudoref, there's nothing to do. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent ae07777 commit 6ee1821

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

refs.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,9 @@ static int write_pseudoref(const char *pseudoref, const struct object_id *oid,
583583
struct strbuf buf = STRBUF_INIT;
584584
int ret = -1;
585585

586+
if (!oid)
587+
return 0;
588+
586589
strbuf_addf(&buf, "%s\n", oid_to_hex(oid));
587590

588591
filename = git_path("%s", pseudoref);

0 commit comments

Comments
 (0)