@matheusbsbs / matheus-bagliano / commits / 6836d2fe06
Fork 0

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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Dec 20, 2019 at 09:55 UTC 6836d2fe06cea750ba7364895f8f37c32a34408c
1 file changed +1 -1
dir.c
+1 -1
@@ -2154,7 +2154,7 @@ static int treat_leading_path(struct dir_struct *dir,
2154 * For either case, padding with len+1 bytes at the end will ensure
2155 * sufficient storage space.
2156 */
2157 - de = xcalloc(1, sizeof(struct dirent)+len+1);
2157 + de = xcalloc(1, st_add3(sizeof(struct dirent), len, 1));
2158 memset(&cdir, 0, sizeof(cdir));
2159 cdir.de = de;
2160 #if defined(DT_UNKNOWN) && !defined(NO_D_TYPE_IN_DIRENT)