dir.c: clean the entire struct in clear_exclude_list()
PATCH 1/1 dir.c: clean the entire struct in clear_exclude_list()
Make sure "el" can be reuseable again. The problem was el->alloc is not cleared and may cause segfaults next time because add_exclude() thinks el->excludes (being NULL) has enough space. Just clear the entire struct to be safe.
---
This was needed in the worktree config split series because the same exclude_list could be reused. But that series is changing and will not need exclude_list any more. So instead of dropping this patch, I submit it separately. It's a good fix anyway.
dir.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
dir.c +1 -3
@@ -564,9 +564,7 @@ void clear_exclude_list(struct exclude_list *el)free (el->excludes);free (el->filebuf); - el->nr =0 ; - el->excludes =NULL ; - el->filebuf =NULL ; +memset (el,0 ,sizeof (*el)); }static void trim_trailing_spaces (char *buf)
Signature · 1 line
2.3.0.rc1.137.g477eb31
Quoted 4 lines · Nguyễn Thái Ngọc Duy
Make sure "el" can be reuseable again. The problem was
el->allocis not cleared and may cause segfaults next time becauseadd_exclude()thinksel->excludes(being NULL) has enough space. Just clear the entire struct to be safe.
OK.
If somebody ever adds a field to this structure that should not be cleared by filling it with '\0', that person would notice and turn this memset() back to individual field assignment, but until then, I think memset is a reasonable thing to do, as that is how it is initialized by add_exclude_list() in the first place anyway.
Will apply.
Quoted 25 lines
Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>---
This was needed in the worktree config split series because the sameexclude_listcould be reused. But that series is changing and will not needexclude_listany more. So instead of dropping this patch, I submit it separately. It's a good fix anyway.dir.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)dir.c +1
-3@@ -564,9 +564,7 @@ void clear_exclude_list(struct exclude_list *el)free (el->excludes);free (el->filebuf); - el->nr =0 ; - el->excludes =NULL ; - el->filebuf =NULL ; +memset (el,0 ,sizeof (*el)); }static void trim_trailing_spaces (char *buf)