mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-30 22:24:56 +00:00
Merge pull request #1591 from arrbee/reorder-reuc-read-for-safety
Ensure reuc vector is always valid
This commit is contained in:
commit
18e37db935
14
src/index.c
14
src/index.c
@ -1283,8 +1283,9 @@ static int read_reuc(git_index *index, const char *buffer, size_t size)
|
|||||||
size_t len;
|
size_t len;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* This gets called multiple times, the vector might already be initialized */
|
/* If called multiple times, the vector might already be initialized */
|
||||||
if (index->reuc._alloc_size == 0 && git_vector_init(&index->reuc, 16, reuc_cmp) < 0)
|
if (index->reuc._alloc_size == 0 &&
|
||||||
|
git_vector_init(&index->reuc, 16, reuc_cmp) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
while (size) {
|
while (size) {
|
||||||
@ -1294,12 +1295,9 @@ static int read_reuc(git_index *index, const char *buffer, size_t size)
|
|||||||
if (size <= len)
|
if (size <= len)
|
||||||
return index_error_invalid("reading reuc entries");
|
return index_error_invalid("reading reuc entries");
|
||||||
|
|
||||||
lost = git__malloc(sizeof(git_index_reuc_entry));
|
lost = git__calloc(1, sizeof(git_index_reuc_entry));
|
||||||
GITERR_CHECK_ALLOC(lost);
|
GITERR_CHECK_ALLOC(lost);
|
||||||
|
|
||||||
if (git_vector_insert(&index->reuc, lost) < 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
/* read NUL-terminated pathname for entry */
|
/* read NUL-terminated pathname for entry */
|
||||||
lost->path = git__strdup(buffer);
|
lost->path = git__strdup(buffer);
|
||||||
GITERR_CHECK_ALLOC(lost->path);
|
GITERR_CHECK_ALLOC(lost->path);
|
||||||
@ -1337,6 +1335,10 @@ static int read_reuc(git_index *index, const char *buffer, size_t size)
|
|||||||
size -= 20;
|
size -= 20;
|
||||||
buffer += 20;
|
buffer += 20;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* entry was read successfully - insert into reuc vector */
|
||||||
|
if (git_vector_insert(&index->reuc, lost) < 0)
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* entries are guaranteed to be sorted on-disk */
|
/* entries are guaranteed to be sorted on-disk */
|
||||||
|
Loading…
Reference in New Issue
Block a user