Skip to content

Commit cc21682

Browse files
Jim Meyeringgitster
authored andcommitted
Don't dereference NULL upon lookup failure.
Instead, signal the error just like the case we do upon encountering an object with an unknown type. Signed-off-by: Jim Meyering <meyering@redhat.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 97bc00a commit cc21682

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

object.c

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -136,29 +136,38 @@ struct object *parse_object_buffer(const unsigned char *sha1, enum object_type t
136136
struct object *obj;
137137
int eaten = 0;
138138

139+
obj = NULL;
139140
if (type == OBJ_BLOB) {
140141
struct blob *blob = lookup_blob(sha1);
141-
parse_blob_buffer(blob, buffer, size);
142-
obj = &blob->object;
142+
if (blob) {
143+
parse_blob_buffer(blob, buffer, size);
144+
obj = &blob->object;
145+
}
143146
} else if (type == OBJ_TREE) {
144147
struct tree *tree = lookup_tree(sha1);
145-
obj = &tree->object;
146-
if (!tree->object.parsed) {
147-
parse_tree_buffer(tree, buffer, size);
148-
eaten = 1;
148+
if (tree) {
149+
obj = &tree->object;
150+
if (!tree->object.parsed) {
151+
parse_tree_buffer(tree, buffer, size);
152+
eaten = 1;
153+
}
149154
}
150155
} else if (type == OBJ_COMMIT) {
151156
struct commit *commit = lookup_commit(sha1);
152-
parse_commit_buffer(commit, buffer, size);
153-
if (!commit->buffer) {
154-
commit->buffer = buffer;
155-
eaten = 1;
157+
if (commit) {
158+
parse_commit_buffer(commit, buffer, size);
159+
if (!commit->buffer) {
160+
commit->buffer = buffer;
161+
eaten = 1;
162+
}
163+
obj = &commit->object;
156164
}
157-
obj = &commit->object;
158165
} else if (type == OBJ_TAG) {
159166
struct tag *tag = lookup_tag(sha1);
160-
parse_tag_buffer(tag, buffer, size);
161-
obj = &tag->object;
167+
if (tag) {
168+
parse_tag_buffer(tag, buffer, size);
169+
obj = &tag->object;
170+
}
162171
} else {
163172
warning("object %s has unknown type id %d\n", sha1_to_hex(sha1), type);
164173
obj = NULL;

0 commit comments

Comments
 (0)