From: brian m. carlson Date: Sun, 15 Oct 2017 22:06:52 +0000 (+0000) Subject: refs: prevent accidental NULL dereference in write_pseudoref X-Git-Tag: v2.16.0-rc0~163^2~20 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/6ee18216d8d9ca8f76b01282b36bdf590a64d8fc?ds=inline;hp=ae077771b09fac4d663e3f8c039318a97eb3a15b 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 Signed-off-by: Junio C Hamano --- diff --git a/refs.c b/refs.c index edd20044c6..91c2af78b6 100644 --- a/refs.c +++ b/refs.c @@ -583,6 +583,9 @@ static int write_pseudoref(const char *pseudoref, const struct object_id *oid, struct strbuf buf = STRBUF_INIT; int ret = -1; + if (!oid) + return 0; + strbuf_addf(&buf, "%s\n", oid_to_hex(oid)); filename = git_path("%s", pseudoref);