ref: f53d3b524f2d848fad5a34b4883ee9a3602b6f79
parent: e1e1a6cb1b310dbd811c7ebbd167811f5300d597
author: Ori Bernstein <[email protected]>
date: Tue Feb 23 11:04:15 EST 2021
ref.c: be more paranoid about object types If a tag does not point at a commit object, we will crash at the moment. Warn instead.
--- a/ref.c
+++ b/ref.c
@@ -273,9 +273,15 @@
if(hasheq(&head[i], &Zhash))
continue;
if((o = readobject(head[i])) == nil){
+ fprint(2, "warning: %H does not point at commit\n", o->hash);
werrstr("read head %H: %r", head[i]);
return -1;
}
+ if(o->type != GCommit){
+ fprint(2, "warning: %H does not point at commit\n", o->hash);
+ unref(o);
+ continue;
+ }
dprint(1, "twixt init: keep %H\n", o->hash);
e = emalloc(sizeof(Objq));
e->o = o;
@@ -287,10 +293,15 @@
for(i = 0; i < ntail; i++){
if(hasheq(&tail[i], &Zhash))
continue;
- if((o = readobject(tail[i])) == nil){
+ if((o = readobject(head[i])) == nil){
+ fprint(2, "warning: %H does not point at commit\n", o->hash);
werrstr("read tail %H: %r", tail[i]);
return -1;
}
+ if(o->type != GCommit){
+ unref(o);
+ continue;
+ }
dprint(1, "init: drop %H\n", o->hash);
e = emalloc(sizeof(Objq));
e->o = o;
@@ -322,6 +333,11 @@
for(i = 0; i < q->o->commit->nparent; i++){
if((c = readobject(q->o->commit->parent[i])) == nil)
goto error;
+ if(c->type != GCommit){
+ fprint(2, "warning: %H does not point at commit\n", c->hash);
+ unref(c);
+ continue;
+ }
dprint(2, "enqueue: %s %H\n", q->color == Keep ? "keep" : "drop", c->hash);
n = emalloc(sizeof(Objq));
n->color = q->color;