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:
-rw-r--r--src/signature.c9
-rw-r--r--src/util.h15
2 files changed, 18 insertions, 6 deletions
diff --git a/src/signature.c b/src/signature.c
index ab5882b95..a18f10474 100644
--- a/src/signature.c
+++ b/src/signature.c
@@ -133,17 +133,14 @@ int git_signature__parse(git_signature *sig, const char **buffer_out,
if (header) {
const size_t header_len = strlen(header);
- if (buffer_end - buffer < header_len || memcmp(buffer, header, header_len) != 0)
+ if (buffer + header_len >= buffer_end || memcmp(buffer, header, header_len) != 0)
return signature_error("expected prefix doesn't match actual");
buffer += header_len;
}
- if (buffer >= buffer_end)
- return signature_error("signature too short");
-
- email_start = memrchr(buffer, '<', buffer_end - buffer);
- email_end = memrchr(buffer, '>', buffer_end - buffer);
+ email_start = git__memrchr(buffer, '<', buffer_end - buffer);
+ email_end = git__memrchr(buffer, '>', buffer_end - buffer);
if (!email_start || !email_end || email_end <= email_start)
return signature_error("malformed e-mail");
diff --git a/src/util.h b/src/util.h
index 351ff422b..9dbcb6a4f 100644
--- a/src/util.h
+++ b/src/util.h
@@ -127,6 +127,21 @@ GIT_INLINE(const char *) git__next_line(const char *s)
return s;
}
+GIT_INLINE(const void *) git__memrchr(const void *s, int c, size_t n)
+{
+ const unsigned char *cp;
+
+ if (n != 0) {
+ cp = (unsigned char *)s + n;
+ do {
+ if (*(--cp) == (unsigned char)c)
+ return cp;
+ } while (--n != 0);
+ }
+
+ return NULL;
+}
+
typedef int (*git__tsort_cmp)(const void *a, const void *b);
extern void git__tsort(void **dst, size_t size, git__tsort_cmp cmp);