diff options
| author | Junio C Hamano <gitster@pobox.com> | 2023-09-14 11:16:59 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2023-09-14 11:16:59 -0700 |
| commit | 174dfe463778680382d32a280ad73bc12e2017d3 (patch) | |
| tree | ad21d985a01f21c35fd13fbe5702b1c9f0c77ca5 /tree.c | |
| parent | 6a4e7440fb4b20822e1854925c0dcfae0c64402d (diff) | |
| parent | 4d5693ba05ae0d722ad5a6c0e34296caf6be9b74 (diff) | |
| download | git-174dfe463778680382d32a280ad73bc12e2017d3.tar.xz | |
Merge branch 'jk/tree-name-and-depth-limit'
We now limit depth of the tree objects and maximum length of
pathnames recorded in tree objects.
* jk/tree-name-and-depth-limit:
lower core.maxTreeDepth default to 2048
tree-diff: respect max_allowed_tree_depth
list-objects: respect max_allowed_tree_depth
read_tree(): respect max_allowed_tree_depth
traverse_trees(): respect max_allowed_tree_depth
add core.maxTreeDepth config
fsck: detect very large tree pathnames
tree-walk: rename "error" variable
tree-walk: drop MAX_TRAVERSE_TREES macro
tree-walk: reduce stack size for recursive functions
Diffstat (limited to 'tree.c')
| -rw-r--r-- | tree.c | 9 |
1 files changed, 7 insertions, 2 deletions
@@ -10,11 +10,13 @@ #include "alloc.h" #include "tree-walk.h" #include "repository.h" +#include "environment.h" const char *tree_type = "tree"; int read_tree_at(struct repository *r, struct tree *tree, struct strbuf *base, + int depth, const struct pathspec *pathspec, read_tree_fn_t fn, void *context) { @@ -24,6 +26,9 @@ int read_tree_at(struct repository *r, int len, oldlen = base->len; enum interesting retval = entry_not_interesting; + if (depth > max_allowed_tree_depth) + return error("exceeded maximum allowed tree depth"); + if (parse_tree(tree)) return -1; @@ -74,7 +79,7 @@ int read_tree_at(struct repository *r, strbuf_add(base, entry.path, len); strbuf_addch(base, '/'); retval = read_tree_at(r, lookup_tree(r, &oid), - base, pathspec, + base, depth + 1, pathspec, fn, context); strbuf_setlen(base, oldlen); if (retval) @@ -89,7 +94,7 @@ int read_tree(struct repository *r, read_tree_fn_t fn, void *context) { struct strbuf sb = STRBUF_INIT; - int ret = read_tree_at(r, tree, &sb, pathspec, fn, context); + int ret = read_tree_at(r, tree, &sb, 0, pathspec, fn, context); strbuf_release(&sb); return ret; } |
