[PATCH v3 05/25] refs: prevent accidental NULL dereference in write_pseudoref
- From
brian m. carlson <sandals@crustytoothpaste.net>
- Date
- Oct 15, 2017, 22:06 UTC
- Message-ID
- <20171015220712.97308-6-sandals@crustytoothpaste.net>
- In-Reply-To
- <20171015220712.97308-1-sandals@crustytoothpaste.net>
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> --- refs.c | 3 +++ 1 file changed, 3 insertions(+)
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);
-- 2.15.0.rc0.271.g36b669edcc