Add a few malloc checks Add checks to see if malloc failed when allocating the tag members and signature members. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
diff --git a/src/signature.c b/src/signature.c
index 7c43979..bd64652 100644
--- a/src/signature.c
+++ b/src/signature.c
@@ -140,6 +140,9 @@ int git_signature__parse(git_signature *sig, const char **buffer_out,
name_length = name_end - buffer - 1;
sig->name = git__malloc(name_length + 1);
+ if (sig->name == NULL)
+ return GIT_ENOMEM;
+
memcpy(sig->name, buffer, name_length);
sig->name[name_length] = 0;
buffer = name_end + 1;
@@ -153,6 +156,9 @@ int git_signature__parse(git_signature *sig, const char **buffer_out,
email_length = email_end - buffer;
sig->email = git__malloc(email_length + 1);
+ if (sig->name == NULL)
+ return GIT_ENOMEM;
+
memcpy(sig->email, buffer, email_length);
sig->email[email_length] = 0;
buffer = email_end + 1;
diff --git a/src/tag.c b/src/tag.c
index c18f042..a340095 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -131,12 +131,17 @@ static int parse_tag_buffer(git_tag *tag, const char *buffer, const char *buffer
text_len = search - buffer;
tag->tag_name = git__malloc(text_len + 1);
+ if (tag->tag_name == NULL)
+ return GIT_ENOMEM;
+
memcpy(tag->tag_name, buffer, text_len);
tag->tag_name[text_len] = '\0';
buffer = search + 1;
tag->tagger = git__malloc(sizeof(git_signature));
+ if (tag->tagger == NULL)
+ return GIT_ENOMEM;
if ((error = git_signature__parse(tag->tagger, &buffer, buffer_end, "tagger ")) != 0) {
free(tag->tag_name);
@@ -147,6 +152,9 @@ static int parse_tag_buffer(git_tag *tag, const char *buffer, const char *buffer
text_len = buffer_end - ++buffer;
tag->message = git__malloc(text_len + 1);
+ if (tag->message == NULL)
+ return GIT_ENOMEM;
+
memcpy(tag->message, buffer, text_len);
tag->message[text_len] = '\0';