mirror of
https://github.com/git/git.git
synced 2024-10-28 12:59:41 +01:00
parse_object_buffer: correct freeing the buffer
If we exit early in the function parse_object_buffer, we did not write to *eaten_p. Then the calling function parse_object, which looks like the following with respect to the eaten variable, cannot rely on a proper value set in eaten, hence the freeing of the buffer depends on random values in memory. struct object *parse_object(const unsigned char *sha1) { int eaten; ... obj = parse_object_buffer(sha1, type, size, buffer, &eaten); if (!eaten) free(buffer); } This change makes sure, the buffer freeing condition is deterministic. Signed-off-by: Stefan Beller <stefanbeller@googlemail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
15999998fb
commit
8e92e8f242
1 changed files with 3 additions and 4 deletions
7
object.c
7
object.c
|
@ -135,7 +135,7 @@ struct object *lookup_unknown_object(const unsigned char *sha1)
|
||||||
struct object *parse_object_buffer(const unsigned char *sha1, enum object_type type, unsigned long size, void *buffer, int *eaten_p)
|
struct object *parse_object_buffer(const unsigned char *sha1, enum object_type type, unsigned long size, void *buffer, int *eaten_p)
|
||||||
{
|
{
|
||||||
struct object *obj;
|
struct object *obj;
|
||||||
int eaten = 0;
|
*eaten_p = 0;
|
||||||
|
|
||||||
obj = NULL;
|
obj = NULL;
|
||||||
if (type == OBJ_BLOB) {
|
if (type == OBJ_BLOB) {
|
||||||
|
@ -154,7 +154,7 @@ struct object *parse_object_buffer(const unsigned char *sha1, enum object_type t
|
||||||
if (!tree->object.parsed) {
|
if (!tree->object.parsed) {
|
||||||
if (parse_tree_buffer(tree, buffer, size))
|
if (parse_tree_buffer(tree, buffer, size))
|
||||||
return NULL;
|
return NULL;
|
||||||
eaten = 1;
|
*eaten_p = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (type == OBJ_COMMIT) {
|
} else if (type == OBJ_COMMIT) {
|
||||||
|
@ -164,7 +164,7 @@ struct object *parse_object_buffer(const unsigned char *sha1, enum object_type t
|
||||||
return NULL;
|
return NULL;
|
||||||
if (!commit->buffer) {
|
if (!commit->buffer) {
|
||||||
commit->buffer = buffer;
|
commit->buffer = buffer;
|
||||||
eaten = 1;
|
*eaten_p = 1;
|
||||||
}
|
}
|
||||||
obj = &commit->object;
|
obj = &commit->object;
|
||||||
}
|
}
|
||||||
|
@ -181,7 +181,6 @@ struct object *parse_object_buffer(const unsigned char *sha1, enum object_type t
|
||||||
}
|
}
|
||||||
if (obj && obj->type == OBJ_NONE)
|
if (obj && obj->type == OBJ_NONE)
|
||||||
obj->type = type;
|
obj->type = type;
|
||||||
*eaten_p = eaten;
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue