unpack-trees: make sure "df_conflict_entry.name" is NUL terminated.
The structure that ends with a flexible array member (or 0 length array with older GCC) "char name[FLEX_ARRAY]" is allocated on the stack and we use it after clearing its entire size with memset. That does not guarantee that "name" is properly NUL terminated as we intended on platforms with more forgiving structure alignment requirements. Reported breakage on m68k by Roman Zippel. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Dec 4, 2006 at 02:11 UTC
0fb1eaa8850557249a8d1c43a4f0f3ac5a5f75ce
1 file changed
+5
-3
unpack-trees.c
+5
-3
@@ -370,7 +370,7 @@ int unpack_trees(struct object_list *trees, struct unpack_trees_options *o)
370
int i;
371
struct object_list *posn = trees;
372
struct tree_entry_list df_conflict_list;
373
- struct cache_entry df_conflict_entry;
373
+ static struct cache_entry *dfc;
374
375
memset(&df_conflict_list, 0, sizeof(df_conflict_list));
376
df_conflict_list.next = &df_conflict_list;
@@ -381,8 +381,10 @@ int unpack_trees(struct object_list *trees, struct unpack_trees_options *o)
381
state.refresh_cache = 1;
382
383
o->merge_size = len;
384
- memset(&df_conflict_entry, 0, sizeof(df_conflict_entry));
385
- o->df_conflict_entry = &df_conflict_entry;
384
+
385
+ if (!dfc)
386
+ dfc = xcalloc(1, sizeof(struct cache_entry) + 1);
387
+ o->df_conflict_entry = dfc;
388
389
if (len) {
390
posns = xmalloc(len * sizeof(struct tree_entry_list *));