Commit 0f1e2d20 by Patrick Steinhardt

index: fix contradicting comparison

The overflow check in `read_reuc` tries to verify if the
`git__strtol32` parses an integer bigger than UINT_MAX. The `tmp`
variable is casted to an unsigned int for this and then checked
for being greater than UINT_MAX, which obviously can never be
true.

Fix this by instead fixing the `mode` field's size in `struct
git_index_reuc_entry` to `uint32_t`. We can now parse the int
with `git__strtol64`, which can never return a value bigger than
`UINT32_MAX`, and additionally checking if the returned value is
smaller than zero.

We do not need to handle overflows explicitly here, as
`git__strtol64` returns an error when the returned value would
overflow.
parent 7808c937
...@@ -25,7 +25,7 @@ typedef struct git_index_name_entry { ...@@ -25,7 +25,7 @@ typedef struct git_index_name_entry {
/** Representation of a resolve undo entry in the index. */ /** Representation of a resolve undo entry in the index. */
typedef struct git_index_reuc_entry { typedef struct git_index_reuc_entry {
unsigned int mode[3]; uint32_t mode[3];
git_oid oid[3]; git_oid oid[3];
char *path; char *path;
} git_index_reuc_entry; } git_index_reuc_entry;
......
...@@ -2135,11 +2135,11 @@ static int read_reuc(git_index *index, const char *buffer, size_t size) ...@@ -2135,11 +2135,11 @@ static int read_reuc(git_index *index, const char *buffer, size_t size)
/* read 3 ASCII octal numbers for stage entries */ /* read 3 ASCII octal numbers for stage entries */
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
int tmp; int64_t tmp;
if (git__strtol32(&tmp, buffer, &endptr, 8) < 0 || if (git__strtol64(&tmp, buffer, &endptr, 8) < 0 ||
!endptr || endptr == buffer || *endptr || !endptr || endptr == buffer || *endptr ||
(unsigned)tmp > UINT_MAX) { tmp < 0) {
index_entry_reuc_free(lost); index_entry_reuc_free(lost);
return index_error_invalid("reading reuc entry stage"); return index_error_invalid("reading reuc entry stage");
} }
......
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