diff options
author | Patrick Steinhardt <ps@pks.im> | 2018-08-09 12:48:26 +0200 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2018-08-09 12:56:47 +0200 |
commit | c65568d8c8c1bf4920393190e862819cd263f439 (patch) | |
tree | de2b2de373c2d58da38fde7a6e21766532faf7e8 /src/diff_tform.c | |
parent | 9275d84c583a030e759edbfafacf99c42a83c543 (diff) | |
download | libgit2-c65568d8c8c1bf4920393190e862819cd263f439.tar.gz |
diff: fix OOM on AIX when finding similar deltas in empty diff
The function `git_diff_find_similar` keeps a function of cache
similarity metrics signatures, whose size depends on the number of
deltas passed in via the `diff` parameter. In case where the diff is
empty and thus doesn't have any deltas at all, we may end up allocating
this cache via a call to `git__calloc(0, sizeof(void *))`. At least on
AIX, allocating 0 bytes will result in a `NULL` pointer being returned,
which causes us to erroneously return an OOM error.
Fix this situation by simply returning early in case where we are being
passed an empty diff, as we cannot find any similarities in that case
anyway.
Diffstat (limited to 'src/diff_tform.c')
-rw-r--r-- | src/diff_tform.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/diff_tform.c b/src/diff_tform.c index 71330654a..42da15065 100644 --- a/src/diff_tform.c +++ b/src/diff_tform.c @@ -822,7 +822,7 @@ int git_diff_find_similar( num_deltas = diff->deltas.length; /* TODO: maybe abort if deltas.length > rename_limit ??? */ - if (!git__is_uint32(num_deltas)) + if (!num_deltas || !git__is_uint32(num_deltas)) goto cleanup; /* No flags set; nothing to do */ |