diff options
| author | nulltoken <emeric.fermas@gmail.com> | 2011-10-29 17:40:04 +0200 |
|---|---|---|
| committer | nulltoken <emeric.fermas@gmail.com> | 2011-10-29 22:05:56 +0200 |
| commit | d1db74bf57999ac336fddadf2f9ee7c24961268f (patch) | |
| tree | 31d630f4d82ef2d5c4b46a54a3e7d94f8e95944e /src/status.c | |
| parent | 3286c408eccb18c525ca123383f3ebf5097441bc (diff) | |
| download | libgit2-d1db74bf57999ac336fddadf2f9ee7c24961268f.tar.gz | |
status: Prevent segfaulting when determining the status of a repository
Fixes #465
Diffstat (limited to 'src/status.c')
| -rw-r--r-- | src/status.c | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/src/status.c b/src/status.c index 1fc3794ea..a3d6ee897 100644 --- a/src/status.c +++ b/src/status.c @@ -183,26 +183,28 @@ static int process_folder(struct status_st *st, const git_tree_entry *tree_entry git_object *subtree = NULL; git_tree *pushed_tree = NULL; int error, pushed_tree_position = 0; - git_otype tree_entry_type; - - tree_entry_type = git_tree_entry_type(tree_entry); - - switch (tree_entry_type) { - case GIT_OBJ_TREE: - error = git_tree_entry_2object(&subtree, ((git_object *)(st->tree))->repo, tree_entry); - pushed_tree = st->tree; - pushed_tree_position = st->tree_position; - st->tree = (git_tree *)subtree; - st->tree_position = 0; - st->head_tree_relative_path_len += 1 + tree_entry->filename_len; /* path + '/' + name */ - break; - - case GIT_OBJ_BLOB: - /* No op */ - break; - - default: - error = git__throw(GIT_EINVALIDTYPE, "Unexpected tree entry type"); /* TODO: How should we deal with submodules? */ + git_otype tree_entry_type = GIT_OBJ_BAD; + + if (tree_entry != NULL) { + tree_entry_type = git_tree_entry_type(tree_entry); + + switch (tree_entry_type) { + case GIT_OBJ_TREE: + error = git_tree_entry_2object(&subtree, ((git_object *)(st->tree))->repo, tree_entry); + pushed_tree = st->tree; + pushed_tree_position = st->tree_position; + st->tree = (git_tree *)subtree; + st->tree_position = 0; + st->head_tree_relative_path_len += 1 + tree_entry->filename_len; /* path + '/' + name */ + break; + + case GIT_OBJ_BLOB: + /* No op */ + break; + + default: + error = git__throw(GIT_EINVALIDTYPE, "Unexpected tree entry type"); /* TODO: How should we deal with submodules? */ + } } if (full_path != NULL && path_type == GIT_STATUS_PATH_FOLDER) |
