read-tree() and unpack_trees(): use consistent limit
read-tree -m can read up to MAX_TREES, which was arbitrarily set to 8 since August 2007 (4 is needed to deal with 2 merge-base case). However, the updated unpack_trees() code had an advertised limit of 4 (which it enforced). In reality the code was prepared to take only 3 trees and giving 4 caused it to stomp on its stack. Rename the MAX_TREES constant to MAX_UNPACK_TREES, move it to the unpack-trees.h common header file, and use it from both places to avoid future confusion. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Mar 13, 2008 at 22:07 UTC
ca885a4fe6444bed840295378848904106c87c85
3 files changed
+9
-8
builtin-read-tree.c
+4
-5
@@ -13,16 +13,15 @@
13
#include "dir.h"
14
#include "builtin.h"
15
16
-#define MAX_TREES 8
16
static int nr_trees;
18
-static struct tree *trees[MAX_TREES];
17
+static struct tree *trees[MAX_UNPACK_TREES];
18
19
static int list_tree(unsigned char *sha1)
20
{
21
struct tree *tree;
22
24
- if (nr_trees >= MAX_TREES)
25
- die("I cannot read more than %d trees", MAX_TREES);
23
+ if (nr_trees >= MAX_UNPACK_TREES)
24
+ die("I cannot read more than %d trees", MAX_UNPACK_TREES);
25
tree = parse_tree_indirect(sha1);
26
if (!tree)
27
return -1;
@@ -97,7 +96,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
96
{
97
int i, newfd, stage = 0;
98
unsigned char sha1[20];
100
- struct tree_desc t[MAX_TREES];
99
+ struct tree_desc t[MAX_UNPACK_TREES];
100
struct unpack_trees_options opts;
101
102
memset(&opts, 0, sizeof(opts));
unpack-trees.c
+3
-3
@@ -123,7 +123,7 @@ static int unpack_index_entry(struct cache_entry *ce, struct unpack_trees_option
123
int traverse_trees_recursive(int n, unsigned long dirmask, unsigned long df_conflicts, struct name_entry *names, struct traverse_info *info)
124
{
125
int i;
126
- struct tree_desc t[3];
126
+ struct tree_desc t[MAX_UNPACK_TREES];
127
struct traverse_info newinfo;
128
struct name_entry *p;
129
@@ -327,8 +327,8 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
327
{
328
static struct cache_entry *dfc;
329
330
- if (len > 4)
331
- die("unpack_trees takes at most four trees");
330
+ if (len > MAX_UNPACK_TREES)
331
+ die("unpack_trees takes at most %d trees", MAX_UNPACK_TREES);
332
memset(&state, 0, sizeof(state));
333
state.base_dir = "";
334
state.force = 1;
unpack-trees.h
+2
@@ -1,6 +1,8 @@
1
#ifndef UNPACK_TREES_H
2
#define UNPACK_TREES_H
3
4
+#define MAX_UNPACK_TREES 8
5
+
6
struct unpack_trees_options;
7
8
typedef int (*merge_fn_t)(struct cache_entry **src,