diff options
| author | Carlos Martín Nieto <carlos@cmartin.tk> | 2012-06-19 23:36:36 +0200 |
|---|---|---|
| committer | Carlos Martín Nieto <carlos@cmartin.tk> | 2012-06-19 23:47:17 +0200 |
| commit | 053b5096680dd9eaeb679f673f5924a05fe514d9 (patch) | |
| tree | 7e60cfa7885b9390fb41ce6cb6cdf18d7cc69d97 /src/revparse.c | |
| parent | 1b0ef5aa03fad68105784d5d4d87592ce005e03a (diff) | |
| download | libgit2-053b5096680dd9eaeb679f673f5924a05fe514d9.tar.gz | |
revparse: handle a non-existent path in the colon syntax
oid_for_tree_path may not always find the path in the tree, in which
case we need to return an error. The current code doesn't do this and
results in undefined behavior.
Diffstat (limited to 'src/revparse.c')
| -rw-r--r-- | src/revparse.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/revparse.c b/src/revparse.c index 0c053b397..1f0e7da34 100644 --- a/src/revparse.c +++ b/src/revparse.c @@ -567,6 +567,7 @@ static int handle_colon_syntax(git_object **out, { git_tree *tree; git_oid oid; + int error; /* Dereference until we reach a tree. */ if (dereference_to_type(&obj, obj, GIT_OBJ_TREE) < 0) { @@ -575,8 +576,12 @@ static int handle_colon_syntax(git_object **out, tree = (git_tree*)obj; /* Find the blob at the given path. */ - oid_for_tree_path(&oid, tree, repo, path); + error = oid_for_tree_path(&oid, tree, repo, path); git_tree_free(tree); + + if (error < 0) + return error; + return git_object_lookup(out, repo, &oid, GIT_OBJ_ANY); } |
