mirror of
https://github.com/git/git.git
synced 2024-11-23 18:05:29 +08:00
tree-walk: copy object ID before use
In a future commit, the pointer returned by tree_entry_extract will point into the struct tree_desc, causing its lifetime to be bound to that of the struct tree_desc itself. To ensure this code path keeps working, copy the object_id into a local variable so that it lives long enough. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
ecbdaf0899
commit
0a3faa45b1
10
tree-walk.c
10
tree-walk.c
@ -498,10 +498,10 @@ static int find_tree_entry(struct tree_desc *t, const char *name, struct object_
|
|||||||
int namelen = strlen(name);
|
int namelen = strlen(name);
|
||||||
while (t->size) {
|
while (t->size) {
|
||||||
const char *entry;
|
const char *entry;
|
||||||
const struct object_id *oid;
|
struct object_id oid;
|
||||||
int entrylen, cmp;
|
int entrylen, cmp;
|
||||||
|
|
||||||
oid = tree_entry_extract(t, &entry, mode);
|
oidcpy(&oid, tree_entry_extract(t, &entry, mode));
|
||||||
entrylen = tree_entry_len(&t->entry);
|
entrylen = tree_entry_len(&t->entry);
|
||||||
update_tree_entry(t);
|
update_tree_entry(t);
|
||||||
if (entrylen > namelen)
|
if (entrylen > namelen)
|
||||||
@ -512,7 +512,7 @@ static int find_tree_entry(struct tree_desc *t, const char *name, struct object_
|
|||||||
if (cmp < 0)
|
if (cmp < 0)
|
||||||
break;
|
break;
|
||||||
if (entrylen == namelen) {
|
if (entrylen == namelen) {
|
||||||
oidcpy(result, oid);
|
oidcpy(result, &oid);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (name[entrylen] != '/')
|
if (name[entrylen] != '/')
|
||||||
@ -520,10 +520,10 @@ static int find_tree_entry(struct tree_desc *t, const char *name, struct object_
|
|||||||
if (!S_ISDIR(*mode))
|
if (!S_ISDIR(*mode))
|
||||||
break;
|
break;
|
||||||
if (++entrylen == namelen) {
|
if (++entrylen == namelen) {
|
||||||
oidcpy(result, oid);
|
oidcpy(result, &oid);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return get_tree_entry(oid, name + entrylen, result, mode);
|
return get_tree_entry(&oid, name + entrylen, result, mode);
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user