mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-29 05:50:21 +00:00
index: fix potential overflow
mode field of git_index_entry_unmerged is array of unsigned ints. It's unsafe to cast pointer to an element of the array to long int *. It may cause overflow in git_strtol32(). Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
This commit is contained in:
parent
ae9f771c99
commit
b16692faa3
@ -657,10 +657,14 @@ static int read_unmerged(git_index *index, const char *buffer, size_t size)
|
|||||||
buffer += len;
|
buffer += len;
|
||||||
|
|
||||||
for (i = 0; i < 3; i++) {
|
for (i = 0; i < 3; i++) {
|
||||||
if (git__strtol32((long int *) &lost->mode[i], buffer, &endptr, 8) < GIT_SUCCESS ||
|
long tmp;
|
||||||
!endptr || endptr == buffer || *endptr)
|
|
||||||
|
if (git__strtol32(&tmp, buffer, &endptr, 8) < GIT_SUCCESS ||
|
||||||
|
!endptr || endptr == buffer || *endptr || tmp > UINT_MAX)
|
||||||
return GIT_ERROR;
|
return GIT_ERROR;
|
||||||
|
|
||||||
|
lost->mode[i] = tmp;
|
||||||
|
|
||||||
len = (endptr + 1) - buffer;
|
len = (endptr + 1) - buffer;
|
||||||
if (size <= len)
|
if (size <= len)
|
||||||
return git__throw(GIT_ERROR, "Failed to read unmerged entries");
|
return git__throw(GIT_ERROR, "Failed to read unmerged entries");
|
||||||
|
Loading…
Reference in New Issue
Block a user