mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-09 18:22:16 +00:00
Merge pull request #181 from carlosmn/errors
Move signature.c and tag.c to the new error handling
This commit is contained in:
commit
97ce36e700
@ -115,22 +115,22 @@ static int parse_timezone_offset(const char *buffer, long *offset_out)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (offset_start[0] != '-' && offset_start[0] != '+')
|
if (offset_start[0] != '-' && offset_start[0] != '+')
|
||||||
return GIT_EOBJCORRUPTED;
|
return git__throw(GIT_EOBJCORRUPTED, "Failed to parse TZ offset. It doesn't start with '+' or '-'");
|
||||||
|
|
||||||
if (git__strtol32(&dec_offset, offset_start + 1, &offset_end, 10) < GIT_SUCCESS)
|
if (git__strtol32(&dec_offset, offset_start + 1, &offset_end, 10) < GIT_SUCCESS)
|
||||||
return GIT_EOBJCORRUPTED;
|
return git__throw(GIT_EOBJCORRUPTED, "Failed to parse TZ offset. It isn't a number");
|
||||||
|
|
||||||
if (offset_end - offset_start != 5)
|
if (offset_end - offset_start != 5)
|
||||||
return GIT_EOBJCORRUPTED;
|
return git__throw(GIT_EOBJCORRUPTED, "Failed to parse TZ offset. Invalid length");
|
||||||
|
|
||||||
hours = dec_offset / 100;
|
hours = dec_offset / 100;
|
||||||
mins = dec_offset % 100;
|
mins = dec_offset % 100;
|
||||||
|
|
||||||
if (hours > 14) // see http://www.worldtimezone.com/faq.html
|
if (hours > 14) // see http://www.worldtimezone.com/faq.html
|
||||||
return GIT_EOBJCORRUPTED;
|
return git__throw(GIT_EOBJCORRUPTED, "Failed to parse TZ offset. Hour value too large");;
|
||||||
|
|
||||||
if (mins > 59)
|
if (mins > 59)
|
||||||
return GIT_EOBJCORRUPTED;
|
return git__throw(GIT_EOBJCORRUPTED, "Failed to parse TZ offset. Minute value too large");
|
||||||
|
|
||||||
offset = (hours * 60) + mins;
|
offset = (hours * 60) + mins;
|
||||||
|
|
||||||
@ -157,19 +157,19 @@ int git_signature__parse(git_signature *sig, const char **buffer_out,
|
|||||||
|
|
||||||
line_end = memchr(buffer, '\n', buffer_end - buffer);
|
line_end = memchr(buffer, '\n', buffer_end - buffer);
|
||||||
if (!line_end)
|
if (!line_end)
|
||||||
return GIT_EOBJCORRUPTED;
|
return git__throw(GIT_EOBJCORRUPTED, "Failed to parse signature. No newline found");;
|
||||||
|
|
||||||
if (buffer + (header_len + 1) > line_end)
|
if (buffer + (header_len + 1) > line_end)
|
||||||
return GIT_EOBJCORRUPTED;
|
return git__throw(GIT_EOBJCORRUPTED, "Failed to parse signature. Signature too short");
|
||||||
|
|
||||||
if (memcmp(buffer, header, header_len) != 0)
|
if (memcmp(buffer, header, header_len) != 0)
|
||||||
return GIT_EOBJCORRUPTED;
|
return git__throw(GIT_EOBJCORRUPTED, "Failed to parse signature. Expected prefix '%s' doesn't match actual", header);
|
||||||
|
|
||||||
buffer += header_len;
|
buffer += header_len;
|
||||||
|
|
||||||
/* Parse name */
|
/* Parse name */
|
||||||
if ((name_end = memchr(buffer, '<', buffer_end - buffer)) == NULL)
|
if ((name_end = memchr(buffer, '<', buffer_end - buffer)) == NULL)
|
||||||
return GIT_EOBJCORRUPTED;
|
return git__throw(GIT_EOBJCORRUPTED, "Failed to parse signature. Can't find e-mail start");
|
||||||
|
|
||||||
name_length = name_end - buffer - 1;
|
name_length = name_end - buffer - 1;
|
||||||
sig->name = git__malloc(name_length + 1);
|
sig->name = git__malloc(name_length + 1);
|
||||||
@ -181,11 +181,11 @@ int git_signature__parse(git_signature *sig, const char **buffer_out,
|
|||||||
buffer = name_end + 1;
|
buffer = name_end + 1;
|
||||||
|
|
||||||
if (buffer >= line_end)
|
if (buffer >= line_end)
|
||||||
return GIT_EOBJCORRUPTED;
|
return git__throw(GIT_EOBJCORRUPTED, "Failed to parse signature. Ended unexpectedly");
|
||||||
|
|
||||||
/* Parse email */
|
/* Parse email */
|
||||||
if ((email_end = memchr(buffer, '>', buffer_end - buffer)) == NULL)
|
if ((email_end = memchr(buffer, '>', buffer_end - buffer)) == NULL)
|
||||||
return GIT_EOBJCORRUPTED;
|
return git__throw(GIT_EOBJCORRUPTED, "Failed to parse signature. Can't find e-mail end");
|
||||||
|
|
||||||
email_length = email_end - buffer;
|
email_length = email_end - buffer;
|
||||||
sig->email = git__malloc(email_length + 1);
|
sig->email = git__malloc(email_length + 1);
|
||||||
@ -197,10 +197,10 @@ int git_signature__parse(git_signature *sig, const char **buffer_out,
|
|||||||
buffer = email_end + 1;
|
buffer = email_end + 1;
|
||||||
|
|
||||||
if (buffer >= line_end)
|
if (buffer >= line_end)
|
||||||
return GIT_EOBJCORRUPTED;
|
return git__throw(GIT_EOBJCORRUPTED, "Failed to parse signature. Ended unexpectedly");
|
||||||
|
|
||||||
if (git__strtol32(&time, buffer, &buffer, 10) < GIT_SUCCESS)
|
if (git__strtol32(&time, buffer, &buffer, 10) < GIT_SUCCESS)
|
||||||
return GIT_EOBJCORRUPTED;
|
return git__throw(GIT_EOBJCORRUPTED, "Failed to parse signature. Timestamp isn't a number");
|
||||||
|
|
||||||
sig->when.time = (time_t)time;
|
sig->when.time = (time_t)time;
|
||||||
|
|
||||||
|
19
src/tag.c
19
src/tag.c
@ -90,13 +90,13 @@ static int parse_tag_buffer(git_tag *tag, const char *buffer, const char *buffer
|
|||||||
int error;
|
int error;
|
||||||
|
|
||||||
if ((error = git__parse_oid(&tag->target, &buffer, buffer_end, "object ")) < 0)
|
if ((error = git__parse_oid(&tag->target, &buffer, buffer_end, "object ")) < 0)
|
||||||
return error;
|
return git__rethrow(error, "Failed to parse tag. Object field invalid");
|
||||||
|
|
||||||
if (buffer + 5 >= buffer_end)
|
if (buffer + 5 >= buffer_end)
|
||||||
return GIT_EOBJCORRUPTED;
|
return git__throw(GIT_EOBJCORRUPTED, "Failed to parse tag. Object too short");
|
||||||
|
|
||||||
if (memcmp(buffer, "type ", 5) != 0)
|
if (memcmp(buffer, "type ", 5) != 0)
|
||||||
return GIT_EOBJCORRUPTED;
|
return git__throw(GIT_EOBJCORRUPTED, "Failed to parse tag. Type field not found");
|
||||||
buffer += 5;
|
buffer += 5;
|
||||||
|
|
||||||
tag->type = GIT_OBJ_BAD;
|
tag->type = GIT_OBJ_BAD;
|
||||||
@ -105,7 +105,7 @@ static int parse_tag_buffer(git_tag *tag, const char *buffer, const char *buffer
|
|||||||
size_t type_length = strlen(tag_types[i]);
|
size_t type_length = strlen(tag_types[i]);
|
||||||
|
|
||||||
if (buffer + type_length >= buffer_end)
|
if (buffer + type_length >= buffer_end)
|
||||||
return GIT_EOBJCORRUPTED;
|
return git__throw(GIT_EOBJCORRUPTED, "Failed to parse tag. Object too short");
|
||||||
|
|
||||||
if (memcmp(buffer, tag_types[i], type_length) == 0) {
|
if (memcmp(buffer, tag_types[i], type_length) == 0) {
|
||||||
tag->type = i;
|
tag->type = i;
|
||||||
@ -115,18 +115,19 @@ static int parse_tag_buffer(git_tag *tag, const char *buffer, const char *buffer
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (tag->type == GIT_OBJ_BAD)
|
if (tag->type == GIT_OBJ_BAD)
|
||||||
return GIT_EOBJCORRUPTED;
|
return git__throw(GIT_EOBJCORRUPTED, "Failed to parse tag. Invalid object type");
|
||||||
|
|
||||||
if (buffer + 4 >= buffer_end)
|
if (buffer + 4 >= buffer_end)
|
||||||
return GIT_EOBJCORRUPTED;
|
return git__throw(GIT_EOBJCORRUPTED, "Failed to parse tag. Object too short");
|
||||||
|
|
||||||
if (memcmp(buffer, "tag ", 4) != 0)
|
if (memcmp(buffer, "tag ", 4) != 0)
|
||||||
return GIT_EOBJCORRUPTED;
|
return git__throw(GIT_EOBJCORRUPTED, "Failed to parse tag. Tag field not found");
|
||||||
|
|
||||||
buffer += 4;
|
buffer += 4;
|
||||||
|
|
||||||
search = memchr(buffer, '\n', buffer_end - buffer);
|
search = memchr(buffer, '\n', buffer_end - buffer);
|
||||||
if (search == NULL)
|
if (search == NULL)
|
||||||
return GIT_EOBJCORRUPTED;
|
return git__throw(GIT_EOBJCORRUPTED, "Failed to parse tag. Object too short");
|
||||||
|
|
||||||
text_len = search - buffer;
|
text_len = search - buffer;
|
||||||
|
|
||||||
@ -218,7 +219,7 @@ static int tag_create(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!git_odb_exists(repo->db, target))
|
if (!git_odb_exists(repo->db, target))
|
||||||
return GIT_ENOTFOUND;
|
return git__throw(GIT_ENOTFOUND, "Failed to create tag. Object to tag doesn't exist");
|
||||||
|
|
||||||
/* Try to find out what the type is */
|
/* Try to find out what the type is */
|
||||||
if (target_type == GIT_OBJ_ANY) {
|
if (target_type == GIT_OBJ_ANY) {
|
||||||
|
Loading…
Reference in New Issue
Block a user