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>
This commit is contained in:
parent
f746bae84e
commit
ca885a4fe6
@ -13,16 +13,15 @@
|
|||||||
#include "dir.h"
|
#include "dir.h"
|
||||||
#include "builtin.h"
|
#include "builtin.h"
|
||||||
|
|
||||||
#define MAX_TREES 8
|
|
||||||
static int nr_trees;
|
static int nr_trees;
|
||||||
static struct tree *trees[MAX_TREES];
|
static struct tree *trees[MAX_UNPACK_TREES];
|
||||||
|
|
||||||
static int list_tree(unsigned char *sha1)
|
static int list_tree(unsigned char *sha1)
|
||||||
{
|
{
|
||||||
struct tree *tree;
|
struct tree *tree;
|
||||||
|
|
||||||
if (nr_trees >= MAX_TREES)
|
if (nr_trees >= MAX_UNPACK_TREES)
|
||||||
die("I cannot read more than %d trees", MAX_TREES);
|
die("I cannot read more than %d trees", MAX_UNPACK_TREES);
|
||||||
tree = parse_tree_indirect(sha1);
|
tree = parse_tree_indirect(sha1);
|
||||||
if (!tree)
|
if (!tree)
|
||||||
return -1;
|
return -1;
|
||||||
@ -97,7 +96,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
|
|||||||
{
|
{
|
||||||
int i, newfd, stage = 0;
|
int i, newfd, stage = 0;
|
||||||
unsigned char sha1[20];
|
unsigned char sha1[20];
|
||||||
struct tree_desc t[MAX_TREES];
|
struct tree_desc t[MAX_UNPACK_TREES];
|
||||||
struct unpack_trees_options opts;
|
struct unpack_trees_options opts;
|
||||||
|
|
||||||
memset(&opts, 0, sizeof(opts));
|
memset(&opts, 0, sizeof(opts));
|
||||||
|
@ -123,7 +123,7 @@ static int unpack_index_entry(struct cache_entry *ce, struct unpack_trees_option
|
|||||||
int traverse_trees_recursive(int n, unsigned long dirmask, unsigned long df_conflicts, struct name_entry *names, struct traverse_info *info)
|
int traverse_trees_recursive(int n, unsigned long dirmask, unsigned long df_conflicts, struct name_entry *names, struct traverse_info *info)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct tree_desc t[3];
|
struct tree_desc t[MAX_UNPACK_TREES];
|
||||||
struct traverse_info newinfo;
|
struct traverse_info newinfo;
|
||||||
struct name_entry *p;
|
struct name_entry *p;
|
||||||
|
|
||||||
@ -327,8 +327,8 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
|
|||||||
{
|
{
|
||||||
static struct cache_entry *dfc;
|
static struct cache_entry *dfc;
|
||||||
|
|
||||||
if (len > 4)
|
if (len > MAX_UNPACK_TREES)
|
||||||
die("unpack_trees takes at most four trees");
|
die("unpack_trees takes at most %d trees", MAX_UNPACK_TREES);
|
||||||
memset(&state, 0, sizeof(state));
|
memset(&state, 0, sizeof(state));
|
||||||
state.base_dir = "";
|
state.base_dir = "";
|
||||||
state.force = 1;
|
state.force = 1;
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#ifndef UNPACK_TREES_H
|
#ifndef UNPACK_TREES_H
|
||||||
#define UNPACK_TREES_H
|
#define UNPACK_TREES_H
|
||||||
|
|
||||||
|
#define MAX_UNPACK_TREES 8
|
||||||
|
|
||||||
struct unpack_trees_options;
|
struct unpack_trees_options;
|
||||||
|
|
||||||
typedef int (*merge_fn_t)(struct cache_entry **src,
|
typedef int (*merge_fn_t)(struct cache_entry **src,
|
||||||
|
Loading…
Reference in New Issue
Block a user