Commit da0e03ce by Patrick Steinhardt

index: avoid out-of-bounds read when reading reuc entry stage

We use `git__strtol64` to parse file modes of the index entries, which
does not limit the parsed buffer length. As the index can be essentially
treated as "untrusted" in that the data stems from the file system, it
may be misformatted and may not contain terminating `NUL` bytes. This
may lead to out-of-bounds reads when trying to parse index entries with
such malformatted modes.

Fix the issue by using `git__strntol64` instead.

(cherry picked from commit 600ceadd)
parent 2b32806b
...@@ -2202,7 +2202,7 @@ static int read_reuc(git_index *index, const char *buffer, size_t size) ...@@ -2202,7 +2202,7 @@ static int read_reuc(git_index *index, const char *buffer, size_t size)
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
int64_t tmp; int64_t tmp;
if (git__strtol64(&tmp, buffer, &endptr, 8) < 0 || if (git__strntol64(&tmp, buffer, size, &endptr, 8) < 0 ||
!endptr || endptr == buffer || *endptr || !endptr || endptr == buffer || *endptr ||
tmp < 0 || tmp > UINT32_MAX) { tmp < 0 || tmp > UINT32_MAX) {
index_entry_reuc_free(lost); index_entry_reuc_free(lost);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment