mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-10 14:23:56 +00:00
pkt: make sure we really only read the length
A pkt-line's length are described in its first four bytes in ASCII hex. Copy this substring to another string before feeding it to git__strtol32. Otherwise, it will read the whole hash. Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
This commit is contained in:
parent
1d27446c60
commit
78fae47878
21
src/pkt.c
21
src/pkt.c
@ -61,14 +61,27 @@ int git_pkt_parse_line(git_pkt **head, const char *line, const char **out)
|
|||||||
{
|
{
|
||||||
int error = GIT_SUCCESS;
|
int error = GIT_SUCCESS;
|
||||||
long int len;
|
long int len;
|
||||||
|
const int num_len = 4;
|
||||||
|
char *num;
|
||||||
const char *num_end;
|
const char *num_end;
|
||||||
git_pkt *pkt;
|
git_pkt *pkt;
|
||||||
|
|
||||||
error = git__strtol32(&len, line, &num_end, 16);
|
num = git__strndup(line, num_len);
|
||||||
if (error < GIT_SUCCESS)
|
if (num == NULL)
|
||||||
return error;
|
return GIT_ENOMEM;
|
||||||
|
|
||||||
line = num_end;
|
error = git__strtol32(&len, num, &num_end, 16);
|
||||||
|
if (error < GIT_SUCCESS) {
|
||||||
|
free(num);
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
if (num_end - num != num_len) {
|
||||||
|
free(num);
|
||||||
|
return git__throw(GIT_EOBJCORRUPTED, "Wrong pkt length");
|
||||||
|
}
|
||||||
|
free(num);
|
||||||
|
|
||||||
|
line += num_len;
|
||||||
/*
|
/*
|
||||||
* TODO: How do we deal with empty lines? Try again? with the next
|
* TODO: How do we deal with empty lines? Try again? with the next
|
||||||
* line?
|
* line?
|
||||||
|
Loading…
Reference in New Issue
Block a user