summaryrefslogtreecommitdiff
path: root/dir.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2019-12-20 17:55:53 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-12-20 17:55:53 (GMT)
commit6836d2fe06cea750ba7364895f8f37c32a34408c (patch)
tree8258b87863ec384ad4a7a955e5ff375fa4684c71 /dir.c
parentc847dfafeee8b0fe3e053ac307de88e04d1ad072 (diff)
downloadgit-6836d2fe06cea750ba7364895f8f37c32a34408c.zip
git-6836d2fe06cea750ba7364895f8f37c32a34408c.tar.gz
git-6836d2fe06cea750ba7364895f8f37c32a34408c.tar.bz2
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>
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/dir.c b/dir.c
index e1b74f6..113170a 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)