mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-28 17:46:09 +00:00
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>
This commit is contained in:
parent
4a34b3a9ff
commit
076141a137
@ -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;
|
||||
|
@ -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';
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user