From: Stefan Beller <stefanbeller@googlemail.com>
To: philipoakley@iee.org, peff@peff.net, j.sixt@viscovery.net,
ramsay@ramsay1.demon.co.uk, gitster@pobox.com,
git@vger.kernel.org
Cc: Stefan Beller <stefanbeller@googlemail.com>
Subject: [PATCH] parse_object_buffer: Correct freeing the buffer.
Date: Thu, 18 Jul 2013 00:09:42 +0200 [thread overview]
Message-ID: <1374098982-6962-1-git-send-email-stefanbeller@googlemail.com> (raw)
In-Reply-To: <51E715D8.9040307@googlemail.com>
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>
---
object.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/object.c b/object.c
index cbc7333..d8a4b1f 100644
--- a/object.c
+++ b/object.c
@@ -145,7 +145,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 *obj;
- int eaten = 0;
+ *eaten_p = 0;
obj = NULL;
if (type == OBJ_BLOB) {
@@ -164,7 +164,7 @@ struct object *parse_object_buffer(const unsigned char *sha1, enum object_type t
if (!tree->object.parsed) {
if (parse_tree_buffer(tree, buffer, size))
return NULL;
- eaten = 1;
+ *eaten_p = 1;
}
}
} else if (type == OBJ_COMMIT) {
@@ -174,7 +174,7 @@ struct object *parse_object_buffer(const unsigned char *sha1, enum object_type t
return NULL;
if (!commit->buffer) {
commit->buffer = buffer;
- eaten = 1;
+ *eaten_p = 1;
}
obj = &commit->object;
}
@@ -191,7 +191,6 @@ struct object *parse_object_buffer(const unsigned char *sha1, enum object_type t
}
if (obj && obj->type == OBJ_NONE)
obj->type = type;
- *eaten_p = eaten;
return obj;
}
--
1.8.3.3.754.g9c3c367.dirty
next prev parent reply other threads:[~2013-07-17 22:09 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-15 17:31 [PATCH] Fix some sparse warnings Ramsay Jones
2013-07-16 5:57 ` Johannes Sixt
2013-07-16 6:21 ` Jeff King
2013-07-16 20:53 ` Philip Oakley
2013-07-16 21:18 ` Stefan Beller
2013-07-16 22:18 ` Philip Oakley
2013-07-17 5:47 ` Johannes Sixt
2013-07-17 22:08 ` Stefan Beller
2013-07-17 22:09 ` Stefan Beller [this message]
2013-07-17 22:16 ` Stefan Beller
2013-07-17 23:22 ` Junio C Hamano
2013-07-18 17:58 ` Ramsay Jones
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1374098982-6962-1-git-send-email-stefanbeller@googlemail.com \
--to=stefanbeller@googlemail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=j.sixt@viscovery.net \
--cc=peff@peff.net \
--cc=philipoakley@iee.org \
--cc=ramsay@ramsay1.demon.co.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).