mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-29 12:24:11 +00:00
signature.c: fix off-by-one error
Signed-off-by: schu <schu-github@schulog.org>
This commit is contained in:
parent
03d88ed415
commit
5274c31a89
@ -62,7 +62,7 @@ static int process_trimming(const char *input, char **storage, const char *input
|
||||
left = skip_leading_spaces(input, input_end);
|
||||
right = skip_trailing_spaces(input, input_end - 1);
|
||||
|
||||
if (right <= left) {
|
||||
if (right < left) {
|
||||
if (fail_when_empty)
|
||||
return git__throw(GIT_EINVALIDARGS, "Failed to trim. Input is either empty or only contains spaces");
|
||||
else
|
||||
|
@ -478,6 +478,31 @@ BEGIN_TEST(signature1, "can not create a signature with empty name or email")
|
||||
must_fail(try_build_signature("nulltoken", " ", 1234567890, 60));
|
||||
END_TEST
|
||||
|
||||
BEGIN_TEST(signature2, "creating a one character signature")
|
||||
git_signature *sign;
|
||||
sign = git_signature_new("x", "foo@bar.baz", 1234567890, 60);
|
||||
must_be_true(sign != NULL);
|
||||
must_pass(strcmp(sign->name, "x"));
|
||||
must_pass(strcmp(sign->email, "foo@bar.baz"));
|
||||
git_signature_free((git_signature *)sign);
|
||||
END_TEST
|
||||
|
||||
BEGIN_TEST(signature3, "creating a two character signature")
|
||||
git_signature *sign;
|
||||
sign = git_signature_new("xx", "x@y.z", 1234567890, 60);
|
||||
must_be_true(sign != NULL);
|
||||
must_pass(strcmp(sign->name, "x"));
|
||||
must_pass(strcmp(sign->email, "foo@bar.baz"));
|
||||
git_signature_free((git_signature *)sign);
|
||||
END_TEST
|
||||
|
||||
BEGIN_TEST(signature4, "creating a zero character signature")
|
||||
git_signature *sign;
|
||||
sign = git_signature_new("", "x@y.z", 1234567890, 60);
|
||||
must_be_true(sign == NULL);
|
||||
END_TEST
|
||||
|
||||
|
||||
/* External declaration for testing the buffer parsing method */
|
||||
int commit_parse_buffer(git_commit *commit, void *data, size_t len, unsigned int parse_flags);
|
||||
|
||||
@ -758,4 +783,7 @@ BEGIN_SUITE(commit)
|
||||
|
||||
ADD_TEST(signature0);
|
||||
ADD_TEST(signature1);
|
||||
ADD_TEST(signature2);
|
||||
ADD_TEST(signature3);
|
||||
ADD_TEST(signature4);
|
||||
END_SUITE
|
||||
|
Loading…
Reference in New Issue
Block a user