diff options
author | Edward Thomson <ethomson@microsoft.com> | 2015-02-09 23:41:13 -0500 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2015-02-12 22:54:46 -0500 |
commit | 392702ee2c88d7d8aaff25f7a84acb73606f9094 (patch) | |
tree | 97a66fe6e488797c6a9c2680ccb31964f61fe340 /src/blame_git.c | |
parent | d24a5312d8ab6d3cdb259e450ec9f1e2e6f3399d (diff) | |
download | libgit2-392702ee2c88d7d8aaff25f7a84acb73606f9094.tar.gz |
allocations: test for overflow of requested size
Introduce some helper macros to test integer overflow from arithmetic
and set error message appropriately.
Diffstat (limited to 'src/blame_git.c')
-rw-r--r-- | src/blame_git.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/blame_git.c b/src/blame_git.c index 72afb852b..05aef5d99 100644 --- a/src/blame_git.c +++ b/src/blame_git.c @@ -35,10 +35,14 @@ static void origin_decref(git_blame__origin *o) /* Given a commit and a path in it, create a new origin structure. */ static int make_origin(git_blame__origin **out, git_commit *commit, const char *path) { - int error = 0; git_blame__origin *o; + size_t path_len = strlen(path); + int error = 0; + + GITERR_CHECK_ALLOC_ADD(sizeof(*o), path_len); + GITERR_CHECK_ALLOC_ADD(sizeof(*o) + path_len, 1); - o = git__calloc(1, sizeof(*o) + strlen(path) + 1); + o = git__calloc(1, sizeof(*o) + path_len + 1); GITERR_CHECK_ALLOC(o); o->commit = commit; o->refcnt = 1; |