]> git.ipfire.org Git - thirdparty/git.git/commitdiff
dir.c: use st_add3() for allocation size
authorJunio C Hamano <gitster@pobox.com>
Fri, 20 Dec 2019 17:55:53 +0000 (09:55 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 20 Dec 2019 17:55:53 +0000 (09:55 -0800)
When preparing a manufactured dirent instance, we add a length of
path to the size of struct to decide how many bytes to allocate.
Make sure this addition does not wrap-around to cause us
underallocate.

Suggested-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
dir.c

diff --git a/dir.c b/dir.c
index e1b74f6478a2d1f2ebe21c2bf714b1fad2b18186..113170aeb9c49d51704e2461e4aeab6213c40185 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -2154,7 +2154,7 @@ static int treat_leading_path(struct dir_struct *dir,
         * For either case, padding with len+1 bytes at the end will ensure
         * sufficient storage space.
         */
-       de = xcalloc(1, sizeof(struct dirent)+len+1);
+       de = xcalloc(1, st_add3(sizeof(struct dirent), len, 1));
        memset(&cdir, 0, sizeof(cdir));
        cdir.de = de;
 #if defined(DT_UNKNOWN) && !defined(NO_D_TYPE_IN_DIRENT)