diff options
| author | Ben Straub <bstraub@github.com> | 2012-06-19 09:24:44 -0700 |
|---|---|---|
| committer | Ben Straub <bstraub@github.com> | 2012-06-19 09:25:55 -0700 |
| commit | 2c90145aad86084dc72400ad0d47ed6e0ce2762f (patch) | |
| tree | d74f6f5632939d0e6336f671751168a0ab5c79f4 | |
| parent | 68f527c4480f0c1e24f29dc0a2337469fe50967f (diff) | |
| download | libgit2-2c90145aad86084dc72400ad0d47ed6e0ce2762f.tar.gz | |
Fix potential segfault in revparse.
| -rw-r--r-- | src/revparse.c | 7 | ||||
| -rw-r--r-- | tests-clar/refs/revparse.c | 1 |
2 files changed, 7 insertions, 1 deletions
diff --git a/src/revparse.c b/src/revparse.c index 4d6ffb56e..0c053b397 100644 --- a/src/revparse.c +++ b/src/revparse.c @@ -406,7 +406,7 @@ static int handle_caret_syntax(git_object **out, git_repository *repo, git_objec *out = newobj2; return 0; } - + /* {/...} -> Walk all commits until we see a commit msg that matches the phrase. */ if (movement[1] == '/') { int retcode = GIT_ERROR; @@ -550,6 +550,11 @@ static int oid_for_tree_path(git_oid *out, git_tree *tree, git_repository *repo, } } + if (!entry) { + giterr_set(GITERR_INVALID, "Invalid tree path '%s'", path); + return GIT_ERROR; + } + git_oid_cpy(out, git_tree_entry_id(entry)); git__free(alloc); return 0; diff --git a/tests-clar/refs/revparse.c b/tests-clar/refs/revparse.c index fda99e9da..c303e1b5f 100644 --- a/tests-clar/refs/revparse.c +++ b/tests-clar/refs/revparse.c @@ -163,6 +163,7 @@ void test_refs_revparse__colon(void) cl_git_fail(git_revparse_single(&g_obj, g_repo, ":/")); cl_git_fail(git_revparse_single(&g_obj, g_repo, ":/not found in any commit")); cl_git_fail(git_revparse_single(&g_obj, g_repo, ":2:README")); + cl_git_fail(git_revparse_single(&g_obj, g_repo, "master:")); test_object("subtrees:ab/4.txt", "d6c93164c249c8000205dd4ec5cbca1b516d487f"); test_object("subtrees:ab/de/fgh/1.txt", "1f67fc4386b2d171e0d21be1c447e12660561f9b"); |
