From: Junio C Hamano Date: Fri, 20 Dec 2019 17:55:53 +0000 (-0800) Subject: dir.c: use st_add3() for allocation size X-Git-Tag: v2.25.0-rc0~1^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6836d2fe06cea750ba7364895f8f37c32a34408c;p=thirdparty%2Fgit.git dir.c: use st_add3() for allocation size 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 Signed-off-by: Junio C Hamano --- diff --git a/dir.c b/dir.c index e1b74f6478..113170aeb9 100644 --- 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)