Skip to content

Commit 6836d2f

Browse files
committed
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c847dfa commit 6836d2f

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

dir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2154,7 +2154,7 @@ static int treat_leading_path(struct dir_struct *dir,
21542154
* For either case, padding with len+1 bytes at the end will ensure
21552155
* sufficient storage space.
21562156
*/
2157-
de = xcalloc(1, sizeof(struct dirent)+len+1);
2157+
de = xcalloc(1, st_add3(sizeof(struct dirent), len, 1));
21582158
memset(&cdir, 0, sizeof(cdir));
21592159
cdir.de = de;
21602160
#if defined(DT_UNKNOWN) && !defined(NO_D_TYPE_IN_DIRENT)

0 commit comments

Comments
 (0)