Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Schubert <schu@schu.io>2012-08-27 12:51:01 +0400
committerMichael Schubert <schu@schu.io>2012-08-27 13:52:32 +0400
commit4e323ef0a822f376dcc8a0716cc7af26f0582a09 (patch)
tree18ef62bef40c7ef25d2d55e21a602b1c7d72ceed /src/revwalk.c
parent2b175ca972f2531e5ef46d24abeb831d90033a33 (diff)
revwalk: refuse push of non-commit objects
Check the type of the pushed object immediately instead of starting the walk and failing in between.
Diffstat (limited to 'src/revwalk.c')
-rw-r--r--src/revwalk.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/revwalk.c b/src/revwalk.c
index 9dff283f5..8b0e93baf 100644
--- a/src/revwalk.c
+++ b/src/revwalk.c
@@ -264,12 +264,7 @@ static int commit_parse(git_revwalk *walk, commit_object *commit)
if ((error = git_odb_read(&obj, walk->odb, &commit->oid)) < 0)
return error;
-
- if (obj->raw.type != GIT_OBJ_COMMIT) {
- git_odb_object_free(obj);
- giterr_set(GITERR_INVALID, "Failed to parse commit. Object is no commit object");
- return -1;
- }
+ assert(obj->raw.type == GIT_OBJ_COMMIT);
error = commit_quick_parse(walk, commit, &obj->raw);
git_odb_object_free(obj);
@@ -515,8 +510,21 @@ static int process_commit_parents(git_revwalk *walk, commit_object *commit)
static int push_commit(git_revwalk *walk, const git_oid *oid, int uninteresting)
{
+ git_object *obj;
+ git_otype type;
commit_object *commit;
+ if (git_object_lookup(&obj, walk->repo, oid, GIT_OBJ_ANY) < 0)
+ return -1;
+
+ type = git_object_type(obj);
+ git_object_free(obj);
+
+ if (type != GIT_OBJ_COMMIT) {
+ giterr_set(GITERR_INVALID, "Object is no commit object");
+ return -1;
+ }
+
commit = commit_lookup(walk, oid);
if (commit == NULL)
return -1; /* error already reported by failed lookup */