threads / patch / 12282

patch, 6 partsProtect peel_ref fallback case from NULL parse_object result

Subject: [PATCH 1/6] Protect peel_ref fallback case from NULL parse_object result

## tl;dr

One message between Feb 24, 2008 and Feb 24, 2008. Diffs are folded; open one to read it.

replies: 0people: 1as markdown or json

Shawn O. Pearce· Feb 24, 2008, 08:07 UTC · lore

If the SHA-1 we are requesting the object for does not exist in the object database we get a NULL back. Accessing the type from that is not likely to succeed on any system.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 refs.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Show changes to refs.c +1 −1
diff --git a/refs.c b/refs.c
index 67d2a50..fb33da1 100644
--- a/refs.c
+++ b/refs.c
@@ -506,7 +506,7 @@ int peel_ref(const char *ref, unsigned char *sha1)
 
 	/* fallback - callers should not call this for unpacked refs */
 	o = parse_object(base);
-	if (o->type == OBJ_TAG) {
+	if (o && o->type == OBJ_TAG) {
 		o = deref_tag(o, ref, 0);
 		if (o) {
 			hashcpy(sha1, o->sha1);
-- 
1.5.4.3.295.g6b554

← back to recent threads