summaryrefslogtreecommitdiff
path: root/src/index.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/index.c')
-rw-r--r--src/index.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/index.c b/src/index.c
index 6a31dd5cb..68bb9e2b9 100644
--- a/src/index.c
+++ b/src/index.c
@@ -411,6 +411,7 @@ static git_index_tree *read_tree_internal(
{
git_index_tree *tree;
const char *name_start, *buffer;
+ long count;
if ((tree = git__malloc(sizeof(git_index_tree))) == NULL)
return NULL;
@@ -429,12 +430,22 @@ static git_index_tree *read_tree_internal(
goto error_cleanup;
/* Blank-terminated ASCII decimal number of entries in this tree */
- tree->entries = strtol(buffer, (char **)&buffer, 10);
+ if (git__strtol32(&count, buffer, &buffer, 10) < GIT_SUCCESS ||
+ count < 0)
+ goto error_cleanup;
+
+ tree->entries = (size_t)count;
+
if (*buffer != ' ' || ++buffer >= buffer_end)
goto error_cleanup;
/* Number of children of the tree, newline-terminated */
- tree->children_count = strtol(buffer, (char **)&buffer, 10);
+ if (git__strtol32(&count, buffer, &buffer, 10) < GIT_SUCCESS ||
+ count < 0)
+ goto error_cleanup;
+
+ tree->children_count = (size_t)count;
+
if (*buffer != '\n' || ++buffer >= buffer_end)
goto error_cleanup;