Skip to content

Commit 6347d64

Browse files
jeffhostetlergitster
authored andcommitted
dir: fix malloc of root untracked_cache_dir
Use FLEX_ALLOC_STR() to allocate the `struct untracked_cache_dir` for the root directory. Get rid of unsafe code that might fail to initialize the `name` field (if FLEX_ARRAY is not 1). This will make it clear that we intend to have a structure with an empty string following it. A problem was observed on Windows where the length of the memset() was too short, so the first byte of the name field was not zeroed. This resulted in the name field having garbage from a previous use of that area of memory. The record for the root directory was then written to the untracked-cache extension in the index. This garbage would then be visible to future commands when they reloaded the untracked-cache extension. Since the directory record for the root directory had garbage in the `name` field, the `t/helper/test-tool dump-untracked-cache` tool printed this garbage as the path prefix (rather than '/') for each directory in the untracked cache as it recursed. Signed-off-by: Jeff Hostetler <[email protected]> Reviewed-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 59ec224 commit 6347d64

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

dir.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2730,11 +2730,8 @@ static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *d
27302730
return NULL;
27312731
}
27322732

2733-
if (!dir->untracked->root) {
2734-
const int len = sizeof(*dir->untracked->root);
2735-
dir->untracked->root = xmalloc(len);
2736-
memset(dir->untracked->root, 0, len);
2737-
}
2733+
if (!dir->untracked->root)
2734+
FLEX_ALLOC_STR(dir->untracked->root, name, "");
27382735

27392736
/* Validate $GIT_DIR/info/exclude and core.excludesfile */
27402737
root = dir->untracked->root;

0 commit comments

Comments
 (0)