diff options
| author | Vicent Marti <tanoku@gmail.com> | 2011-04-09 15:22:11 -0700 |
|---|---|---|
| committer | Vicent Marti <tanoku@gmail.com> | 2011-04-09 15:22:11 -0700 |
| commit | c6e65acae63bd9b251140184679ab4ea0ec5c1a9 (patch) | |
| tree | 42e304af6ea9be7f4f35e3beca314fccc9fddd27 /src/index.c | |
| parent | b918ae40d1dc5116d7631ef822d7b5b39a622c81 (diff) | |
| download | libgit2-c6e65acae63bd9b251140184679ab4ea0ec5c1a9.tar.gz | |
Properly check `strtol` for errors
We are now using a custom `strtol` implementation to make sure we're not
missing any overflow errors.
Diffstat (limited to 'src/index.c')
| -rw-r--r-- | src/index.c | 15 |
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; |
