X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=tree-walk.c;h=142205ddc3e33fb8024171daf4c6b1bee1dba476;hb=f3ec549481827b10609a43bf504517a0e8063a12;hp=8d4b67317f21508a105175686c7ec98a090ed9b5;hpb=f16eb1f6a3f9a1a09a61f0cd07e9c9ff9ee54530;p=git.git diff --git a/tree-walk.c b/tree-walk.c index 8d4b67317..142205ddc 100644 --- a/tree-walk.c +++ b/tree-walk.c @@ -7,6 +7,9 @@ static const char *get_mode(const char *str, unsigned int *modep) unsigned char c; unsigned int mode = 0; + if (*str == ' ') + return NULL; + while ((c = *str++) != ' ') { if (c < '0' || c > '7') return NULL; @@ -16,13 +19,16 @@ static const char *get_mode(const char *str, unsigned int *modep) return str; } -static void decode_tree_entry(struct tree_desc *desc, const void *buf, unsigned long size) +static void decode_tree_entry(struct tree_desc *desc, const char *buf, unsigned long size) { const char *path; unsigned int mode, len; + if (size < 24 || buf[size - 21]) + die("corrupt tree file"); + path = get_mode(buf, &mode); - if (!path) + if (!path || !*path) die("corrupt tree file"); len = strlen(path) + 1;