diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2021-12-04 20:00:41 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-04 20:00:41 -0500 |
commit | 12b53eb0318b0529514ad7e318de70b8325d43f2 (patch) | |
tree | dcec3efee630f9c38e15433302e5c6faec65e517 /src/commit.c | |
parent | 6fdb1b2f55da9593576b096ee2eecce61995fb51 (diff) | |
parent | 9f03ebd14b6beb00a9bed52c0568a13f8d5ebb08 (diff) | |
download | libgit2-12b53eb0318b0529514ad7e318de70b8325d43f2.tar.gz |
Merge pull request #6128 from libgit2/ethomson/object_validation
Introduce `git_object_rawcontent_is_valid`
Diffstat (limited to 'src/commit.c')
-rw-r--r-- | src/commit.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/commit.c b/src/commit.c index 752d98b02..ceaccb331 100644 --- a/src/commit.c +++ b/src/commit.c @@ -395,6 +395,7 @@ static int commit_parse(git_commit *commit, const char *data, size_t size, unsig git_oid parent_id; size_t header_len; git_signature dummy_sig; + int error; GIT_ASSERT_ARG(commit); GIT_ASSERT_ARG(data); @@ -431,14 +432,14 @@ static int commit_parse(git_commit *commit, const char *data, size_t size, unsig commit->author = git__malloc(sizeof(git_signature)); GIT_ERROR_CHECK_ALLOC(commit->author); - if (git_signature__parse(commit->author, &buffer, buffer_end, "author ", '\n') < 0) - return -1; + if ((error = git_signature__parse(commit->author, &buffer, buffer_end, "author ", '\n')) < 0) + return error; } /* Some tools create multiple author fields, ignore the extra ones */ while (!git__prefixncmp(buffer, buffer_end - buffer, "author ")) { - if (git_signature__parse(&dummy_sig, &buffer, buffer_end, "author ", '\n') < 0) - return -1; + if ((error = git_signature__parse(&dummy_sig, &buffer, buffer_end, "author ", '\n')) < 0) + return error; git__free(dummy_sig.name); git__free(dummy_sig.email); @@ -448,8 +449,8 @@ static int commit_parse(git_commit *commit, const char *data, size_t size, unsig commit->committer = git__malloc(sizeof(git_signature)); GIT_ERROR_CHECK_ALLOC(commit->committer); - if (git_signature__parse(commit->committer, &buffer, buffer_end, "committer ", '\n') < 0) - return -1; + if ((error = git_signature__parse(commit->committer, &buffer, buffer_end, "committer ", '\n')) < 0) + return error; if (flags & GIT_COMMIT_PARSE_QUICK) return 0; @@ -493,7 +494,7 @@ static int commit_parse(git_commit *commit, const char *data, size_t size, unsig bad_buffer: git_error_set(GIT_ERROR_OBJECT, "failed to parse bad commit object"); - return -1; + return GIT_EINVALID; } int git_commit__parse_raw(void *commit, const char *data, size_t size) @@ -971,8 +972,10 @@ int git_commit_create_with_signature( /* The first step is to verify that all the tree and parents exist */ parsed = git__calloc(1, sizeof(git_commit)); GIT_ERROR_CHECK_ALLOC(parsed); - if ((error = commit_parse(parsed, commit_content, strlen(commit_content), 0)) < 0) + if (commit_parse(parsed, commit_content, strlen(commit_content), 0) < 0) { + error = -1; goto cleanup; + } if ((error = validate_tree_and_parents(&parents, repo, &parsed->tree_id, commit_parent_from_commit, parsed, NULL, true)) < 0) goto cleanup; |