receive-pack: check object type of sha1 before using them as commits
Signed-off-by: Martin Koegler <mkoegler@auto.tuwien.ac.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Martin Koegler committed
Jan 2, 2008 at 08:39 UTC
eab827072d1e197eb6ccb6f75e7fe86143735f1e
1 file changed
+12
-2
receive-pack.c
+12
-2
@@ -178,11 +178,21 @@ static const char *update(struct command *cmd)
178
if (deny_non_fast_forwards && !is_null_sha1(new_sha1) &&
179
!is_null_sha1(old_sha1) &&
180
!prefixcmp(name, "refs/heads/")) {
181
+ struct object *old_object, *new_object;
182
struct commit *old_commit, *new_commit;
183
struct commit_list *bases, *ent;
184
184
- old_commit = (struct commit *)parse_object(old_sha1);
185
- new_commit = (struct commit *)parse_object(new_sha1);
185
+ old_object = parse_object(old_sha1);
186
+ new_object = parse_object(new_sha1);
187
+
188
+ if (!old_object || !new_object ||
189
+ old_object->type != OBJ_COMMIT ||
190
+ new_object->type != OBJ_COMMIT) {
191
+ error("bad sha1 objects for %s", name);
192
+ return "bad ref";
193
+ }
194
+ old_commit = (struct commit *)old_object;
195
+ new_commit = (struct commit *)new_object;
196
bases = get_merge_bases(old_commit, new_commit, 1);
197
for (ent = bases; ent; ent = ent->next)
198
if (!hashcmp(old_sha1, ent->item->object.sha1))