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/filebuf.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/filebuf.c')
-rw-r--r-- | src/filebuf.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/filebuf.c b/src/filebuf.c index 25f6e52ef..1a9157558 100644 --- a/src/filebuf.c +++ b/src/filebuf.c @@ -271,6 +271,7 @@ int git_filebuf_open(git_filebuf *file, const char *path, int flags, mode_t mode GITERR_CHECK_ALLOC(file->path_original); /* create the locking path by appending ".lock" to the original */ + GITERR_CHECK_ALLOC_ADD(path_len, GIT_FILELOCK_EXTLENGTH); file->path_lock = git__malloc(path_len + GIT_FILELOCK_EXTLENGTH); GITERR_CHECK_ALLOC(file->path_lock); @@ -437,8 +438,8 @@ int git_filebuf_printf(git_filebuf *file, const char *format, ...) } while ((size_t)len + 1 <= space_left); - tmp_buffer = git__malloc(len + 1); - if (!tmp_buffer) { + if (GIT_ALLOC_OVERFLOW_ADD(len, 1) || + !(tmp_buffer = git__malloc(len + 1))) { file->last_error = BUFERR_MEM; return -1; } |