Merge branch 'mk/maint-parse-careful'
authorJunio C Hamano <gitster@pobox.com>
Tue, 19 Feb 2008 04:56:01 +0000 (20:56 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 19 Feb 2008 04:56:01 +0000 (20:56 -0800)
* 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

1  2 
reachable.c
sha1_file.c
sha1_name.c
shallow.c
upload-pack.c
diff --combined reachable.c
index 823e3242ec126a5d55c36b24eb8699a2efecad52,96a984c693b9f2c2c351142157c8a661f412aa82..3b1c18ff9b9060d0dd437ce89aedb8871c66c54c
@@@ -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 41799492f909e19d907fe5d954463f9fba177a4e,0ca7f0dbc6eda54e43240a45f2cff4cf70659fbd..d9da7c8f75c8f44a62661d92b6f8e5266df83a73
@@@ -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 ed3c867d6ad5ed181033950fbcca8daa605e6f20,2575ea77f499f8316064c1c96927f391130946a7..c2805e736b3086a0e33271a4b5c73cea7d2c55cd
@@@ -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 212e62b77ceea1f81c1938f012099e828f45aa85,ab975482d0571fa4b647bb3bc9f5032947dc0f3e..4d90eda19efe0a80c1cb39e8897ab3ed5e6fcf56
+++ 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 de147853b5546f90190654844c765b0ea44902af,d1d2c2a1f77a53417e7bebcd71bffe5b1588f8f3..b26d05331d7eeab4efea01594ecf196bc5fb50ed
@@@ -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;
  }