Commit 4ec197f3 by Ben Straub

Deploy GIT_SIGNATURE_INIT

parent 10711769
...@@ -93,6 +93,9 @@ int git_commit_create( ...@@ -93,6 +93,9 @@ int git_commit_create(
git_odb *odb; git_odb *odb;
assert(git_object_owner((const git_object *)tree) == repo); assert(git_object_owner((const git_object *)tree) == repo);
if (!git_signature__has_valid_version(author) ||
!git_signature__has_valid_version(committer))
return -1;
git_oid__writebuf(&commit, "tree ", git_object_id((const git_object *)tree)); git_oid__writebuf(&commit, "tree ", git_object_id((const git_object *)tree));
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "refs.h" #include "refs.h"
#include "config.h" #include "config.h"
#include "iterator.h" #include "iterator.h"
#include "signature.h"
static int find_subtree_in_current_level( static int find_subtree_in_current_level(
git_tree **out, git_tree **out,
...@@ -455,6 +456,10 @@ int git_note_create( ...@@ -455,6 +456,10 @@ int git_note_create(
git_commit *commit = NULL; git_commit *commit = NULL;
git_tree *tree = NULL; git_tree *tree = NULL;
if (!git_signature__has_valid_version(author) ||
!git_signature__has_valid_version(committer))
return -1;
target = git_oid_allocfmt(oid); target = git_oid_allocfmt(oid);
GITERR_CHECK_ALLOC(target); GITERR_CHECK_ALLOC(target);
...@@ -482,6 +487,10 @@ int git_note_remove(git_repository *repo, const char *notes_ref, ...@@ -482,6 +487,10 @@ int git_note_remove(git_repository *repo, const char *notes_ref,
git_commit *commit = NULL; git_commit *commit = NULL;
git_tree *tree = NULL; git_tree *tree = NULL;
if (!git_signature__has_valid_version(author) ||
!git_signature__has_valid_version(committer))
return -1;
target = git_oid_allocfmt(oid); target = git_oid_allocfmt(oid);
GITERR_CHECK_ALLOC(target); GITERR_CHECK_ALLOC(target);
......
...@@ -112,6 +112,7 @@ static int reflog_parse(git_reflog *log, const char *buf, size_t buf_size) ...@@ -112,6 +112,7 @@ static int reflog_parse(git_reflog *log, const char *buf, size_t buf_size)
entry->committer = git__malloc(sizeof(git_signature)); entry->committer = git__malloc(sizeof(git_signature));
GITERR_CHECK_ALLOC(entry->committer); GITERR_CHECK_ALLOC(entry->committer);
entry->committer->version = GIT_SIGNATURE_VERSION;
if (git_oid_fromstrn(&entry->oid_old, buf, GIT_OID_HEXSZ) < 0) if (git_oid_fromstrn(&entry->oid_old, buf, GIT_OID_HEXSZ) < 0)
goto fail; goto fail;
...@@ -297,6 +298,9 @@ int git_reflog_append(git_reflog *reflog, const git_oid *new_oid, ...@@ -297,6 +298,9 @@ int git_reflog_append(git_reflog *reflog, const git_oid *new_oid,
assert(reflog && new_oid && committer); assert(reflog && new_oid && committer);
if (!git_signature__has_valid_version(committer))
return -1;
if (reflog_entry_new(&entry) < 0) if (reflog_entry_new(&entry) < 0)
return -1; return -1;
......
...@@ -90,6 +90,7 @@ int git_signature_new(git_signature **sig_out, const char *name, const char *ema ...@@ -90,6 +90,7 @@ int git_signature_new(git_signature **sig_out, const char *name, const char *ema
p = git__calloc(1, sizeof(git_signature)); p = git__calloc(1, sizeof(git_signature));
GITERR_CHECK_ALLOC(p); GITERR_CHECK_ALLOC(p);
p->version = GIT_SIGNATURE_VERSION;
if (process_trimming(name, &p->name, name + strlen(name), 1) < 0 || if (process_trimming(name, &p->name, name + strlen(name), 1) < 0 ||
process_trimming(email, &p->email, email + strlen(email), 1) < 0) process_trimming(email, &p->email, email + strlen(email), 1) < 0)
...@@ -263,8 +264,9 @@ int git_signature__parse(git_signature *sig, const char **buffer_out, ...@@ -263,8 +264,9 @@ int git_signature__parse(git_signature *sig, const char **buffer_out,
const char *buffer = *buffer_out; const char *buffer = *buffer_out;
const char *line_end, *name_end, *email_end, *tz_start, *time_start; const char *line_end, *name_end, *email_end, *tz_start, *time_start;
int error = 0; int error = 0;
git_signature initsig = GIT_SIGNATURE_INIT;
memset(sig, 0x0, sizeof(git_signature)); memmove(sig, &initsig, sizeof(git_signature));
if ((line_end = memchr(buffer, ender, buffer_end - buffer)) == NULL) if ((line_end = memchr(buffer, ender, buffer_end - buffer)) == NULL)
return signature_error("no newline given"); return signature_error("no newline given");
......
...@@ -15,4 +15,16 @@ ...@@ -15,4 +15,16 @@
int git_signature__parse(git_signature *sig, const char **buffer_out, const char *buffer_end, const char *header, char ender); int git_signature__parse(git_signature *sig, const char **buffer_out, const char *buffer_end, const char *header, char ender);
void git_signature__writebuf(git_buf *buf, const char *header, const git_signature *sig); void git_signature__writebuf(git_buf *buf, const char *header, const git_signature *sig);
GIT_INLINE(bool) git_signature__has_valid_version(const git_signature *sig)
{
if (!sig)
return true;
if (sig->version > 0 && sig->version <= GIT_SIGNATURE_VERSION)
return true;
giterr_set(GITERR_INVALID, "Invalid version %d on git_signature", sig->version);
return false;
}
#endif #endif
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "git2/stash.h" #include "git2/stash.h"
#include "git2/status.h" #include "git2/status.h"
#include "git2/checkout.h" #include "git2/checkout.h"
#include "signature.h"
static int create_error(int error, const char *msg) static int create_error(int error, const char *msg)
{ {
...@@ -522,6 +523,9 @@ int git_stash_save( ...@@ -522,6 +523,9 @@ int git_stash_save(
assert(out && repo && stasher); assert(out && repo && stasher);
if (!git_signature__has_valid_version(stasher))
return -1;
if ((error = ensure_non_bare_repository(repo)) < 0) if ((error = ensure_non_bare_repository(repo)) < 0)
return error; return error;
......
...@@ -244,6 +244,9 @@ static int git_tag_create__internal( ...@@ -244,6 +244,9 @@ static int git_tag_create__internal(
assert(repo && tag_name && target); assert(repo && tag_name && target);
assert(!create_tag_annotation || (tagger && message)); assert(!create_tag_annotation || (tagger && message));
if (!git_signature__has_valid_version(tagger))
return -1;
if (git_object_owner(target) != repo) { if (git_object_owner(target) != repo) {
giterr_set(GITERR_INVALID, "The given target does not belong to this repository"); giterr_set(GITERR_INVALID, "The given target does not belong to this repository");
return -1; return -1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment