diff options
author | Jeff King <peff@peff.net> | 2016-02-22 17:44:35 -0500 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-02-22 14:51:09 -0800 |
commit | 50a6c8efa2bbeddf46ca34c7765024108202e04b (patch) | |
tree | 0c189695ed6ad8349527cb03d326ef3fb39707cf /sha1_name.c | |
parent | 96ffc06f72f693d80f05059a1f0e5ca9007d5f1b (diff) | |
download | git-50a6c8efa2bbeddf46ca34c7765024108202e04b.tar.gz |
use st_add and st_mult for allocation size computation
If our size computation overflows size_t, we may allocate a
much smaller buffer than we expected and overflow it. It's
probably impossible to trigger an overflow in most of these
sites in practice, but it is easy enough convert their
additions and multiplications into overflow-checking
variants. This may be fixing real bugs, and it makes
auditing the code easier.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sha1_name.c')
-rw-r--r-- | sha1_name.c | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/sha1_name.c b/sha1_name.c index 892db21813..532db4fdc6 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -87,9 +87,8 @@ static void find_short_object_filename(int len, const char *hex_pfx, struct disa * object databases including our own. */ const char *objdir = get_object_directory(); - int objdir_len = strlen(objdir); - int entlen = objdir_len + 43; - fakeent = xmalloc(sizeof(*fakeent) + entlen); + size_t objdir_len = strlen(objdir); + fakeent = xmalloc(st_add3(sizeof(*fakeent), objdir_len, 43)); memcpy(fakeent->base, objdir, objdir_len); fakeent->name = fakeent->base + objdir_len + 1; fakeent->name[-1] = '/'; |