From: Junio C Hamano Date: Tue, 19 Feb 2008 04:56:01 +0000 (-0800) Subject: Merge branch 'mk/maint-parse-careful' X-Git-Tag: v1.5.5-rc0~193 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/ee4f06c0a60d8b17efdd8f6a3332f175f6aafe0e?ds=inline;hp=-c Merge branch 'mk/maint-parse-careful' * mk/maint-parse-careful: peel_onion: handle NULL check return value from parse_commit() in various functions parse_commit: don't fail, if object is NULL revision.c: handle tag->tagged == NULL reachable.c::process_tree/blob: check for NULL process_tag: handle tag->tagged == NULL check results of parse_commit in merge_bases list-objects.c::process_tree/blob: check for NULL reachable.c::add_one_tree: handle NULL from lookup_tree mark_blob/tree_uninteresting: check for NULL get_sha1_oneline: check return value of parse_object read_object_with_reference: don't read beyond the buffer --- ee4f06c0a60d8b17efdd8f6a3332f175f6aafe0e diff --combined reachable.c index 823e3242ec,96a984c693..3b1c18ff9b --- a/reachable.c +++ b/reachable.c @@@ -15,6 -15,8 +15,8 @@@ static void process_blob(struct blob *b { struct object *obj = &blob->object; + if (!blob) + die("bad blob object"); if (obj->flags & SEEN) return; obj->flags |= SEEN; @@@ -39,6 -41,8 +41,8 @@@ static void process_tree(struct tree *t struct name_entry entry; struct name_path me; + if (!tree) + die("bad tree object"); if (obj->flags & SEEN) return; obj->flags |= SEEN; @@@ -79,7 -83,8 +83,8 @@@ static void process_tag(struct tag *tag if (parse_tag(tag) < 0) die("bad tag object %s", sha1_to_hex(obj->sha1)); - add_object(tag->tagged, p, NULL, name); + if (tag->tagged) + add_object(tag->tagged, p, NULL, name); } static void walk_commit_list(struct rev_info *revs) @@@ -150,7 -155,8 +155,8 @@@ static int add_one_reflog(const char *p static void add_one_tree(const unsigned char *sha1, struct rev_info *revs) { struct tree *tree = lookup_tree(sha1); - add_pending_object(revs, &tree->object, ""); + if (tree) + add_pending_object(revs, &tree->object, ""); } static void add_cache_tree(struct cache_tree *it, struct rev_info *revs) @@@ -176,7 -182,7 +182,7 @@@ static void add_cache_refs(struct rev_i * lookup_blob() on them, to avoid populating the hash table * with invalid information */ - if (S_ISGITLINK(ntohl(active_cache[i]->ce_mode))) + if (S_ISGITLINK(active_cache[i]->ce_mode)) continue; lookup_blob(active_cache[i]->sha1); @@@ -215,7 -221,6 +221,7 @@@ void mark_reachable_objects(struct rev_ * Set up the revision walk - this will move all commits * from the pending list to the commit walking list. */ - prepare_revision_walk(revs); + if (prepare_revision_walk(revs)) + die("revision walk setup failed"); walk_commit_list(revs); } diff --combined sha1_file.c index 41799492f9,0ca7f0dbc6..d9da7c8f75 --- a/sha1_file.c +++ b/sha1_file.c @@@ -1943,7 -1943,8 +1943,8 @@@ void *read_object_with_reference(const } ref_length = strlen(ref_type); - if (memcmp(buffer, ref_type, ref_length) || + if (ref_length + 40 > isize || + memcmp(buffer, ref_type, ref_length) || get_sha1_hex((char *) buffer + ref_length, actual_sha1)) { free(buffer); return NULL; @@@ -2358,8 -2359,7 +2359,8 @@@ int index_fd(unsigned char *sha1, int f if ((type == OBJ_BLOB) && S_ISREG(st->st_mode)) { struct strbuf nbuf; strbuf_init(&nbuf, 0); - if (convert_to_git(path, buf, size, &nbuf)) { + if (convert_to_git(path, buf, size, &nbuf, + write_object ? safe_crlf : 0)) { munmap(buf, size); buf = strbuf_detach(&nbuf, &size); re_allocated = 1; diff --combined sha1_name.c index ed3c867d6a,2575ea77f4..c2805e736b --- a/sha1_name.c +++ b/sha1_name.c @@@ -494,8 -494,11 +494,11 @@@ static int peel_onion(const char *name return error("%.*s: expected %s type, but the object dereferences to %s type", len, name, typename(expected_type), typename(o->type)); + if (!o) + return -1; if (!o->parsed) - parse_object(o->sha1); + if (!parse_object(o->sha1)) + return -1; } } return 0; @@@ -578,11 -581,8 +581,11 @@@ static int handle_one_ref(const char *p struct object *object = parse_object(sha1); if (!object) return 0; - if (object->type == OBJ_TAG) + if (object->type == OBJ_TAG) { object = deref_tag(object, path, strlen(path)); + if (!object) + return 0; + } if (object->type != OBJ_COMMIT) return 0; insert_by_date((struct commit *)object, list); @@@ -620,7 -620,8 +623,8 @@@ static int get_sha1_oneline(const char unsigned long size; commit = pop_most_recent_commit(&list, ONELINE_SEEN); - parse_object(commit->object.sha1); + if (!parse_object(commit->object.sha1)) + continue; if (temp_commit_buffer) free(temp_commit_buffer); if (commit->buffer) @@@ -698,7 -699,7 +702,7 @@@ int get_sha1_with_mode(const char *name break; if (ce_stage(ce) == stage) { hashcpy(sha1, ce->sha1); - *mode = ntohl(ce->ce_mode); + *mode = ce->ce_mode; return 0; } pos++; diff --combined shallow.c index 212e62b77c,ab975482d0..4d90eda19e --- a/shallow.c +++ b/shallow.c @@@ -56,7 -56,7 +56,7 @@@ struct commit_list *get_shallow_commits if (i < heads->nr) { commit = (struct commit *) deref_tag(heads->objects[i++].item, NULL, 0); - if (commit->object.type != OBJ_COMMIT) { + if (!commit || commit->object.type != OBJ_COMMIT) { commit = NULL; continue; } @@@ -70,7 -70,8 +70,8 @@@ cur_depth = *(int *)commit->util; } } - parse_commit(commit); + if (parse_commit(commit)) + die("invalid commit"); commit->object.flags |= not_shallow_flag; cur_depth++; for (p = commit->parents, commit = NULL; p; p = p->next) { diff --combined upload-pack.c index de147853b5,d1d2c2a1f7..b26d05331d --- a/upload-pack.c +++ b/upload-pack.c @@@ -129,8 -129,7 +129,8 @@@ static int do_rev_list(int fd, void *cr } setup_revisions(0, NULL, &revs, NULL); } - prepare_revision_walk(&revs); + if (prepare_revision_walk(&revs)) + die("revision walk setup failed"); mark_edges_uninteresting(revs.commits, &revs, show_edge); traverse_commit_list(&revs, show_commit, show_object); return 0; @@@ -534,7 -533,8 +534,8 @@@ static void receive_needs(void /* make sure the real parents are parsed */ unregister_shallow(object->sha1); object->parsed = 0; - parse_commit((struct commit *)object); + if (parse_commit((struct commit *)object)) + die("invalid commit"); parents = ((struct commit *)object)->parents; while (parents) { add_object_array(&parents->item->object, @@@ -576,8 -576,7 +577,8 @@@ static int send_ref(const char *refname } if (o->type == OBJ_TAG) { o = deref_tag(o, refname, 0); - packet_write(1, "%s %s^{}\n", sha1_to_hex(o->sha1), refname); + if (o) + packet_write(1, "%s %s^{}\n", sha1_to_hex(o->sha1), refname); } return 0; }