Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
connect.c: check the commit buffer boundary while parsing.
author
Junio C Hamano
<junkio@cox.net>
Wed, 28 Jun 2006 10:51:00 +0000
(
03:51
-0700)
committer
Junio C Hamano
<junkio@cox.net>
Wed, 28 Jun 2006 10:51:00 +0000
(
03:51
-0700)
Signed-off-by: Junio C Hamano <junkio@cox.net>
commit.c
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
c78963d
)
diff --git
a/commit.c
b/commit.c
index 0327df12324ac77c1d5d82a22ce4b30f1b5c7a18..e51ffa1c6cf5948c0e6c6d0b905fc868f4464ccf 100644
(file)
--- a/
commit.c
+++ b/
commit.c
@@
-236,6
+236,7
@@
static struct commit_graft *lookup_commit_graft(const unsigned char *sha1)
int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size)
{
int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size)
{
+ char *tail = buffer;
char *bufptr = buffer;
unsigned char parent[20];
struct commit_list **pptr;
char *bufptr = buffer;
unsigned char parent[20];
struct commit_list **pptr;
@@
-245,9
+246,10
@@
int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size)
if (item->object.parsed)
return 0;
item->object.parsed = 1;
if (item->object.parsed)
return 0;
item->object.parsed = 1;
- if (memcmp(bufptr, "tree ", 5))
+ tail += size;
+ if (tail <= bufptr + 5 || memcmp(bufptr, "tree ", 5))
return error("bogus commit object %s", sha1_to_hex(item->object.sha1));
return error("bogus commit object %s", sha1_to_hex(item->object.sha1));
- if (get_sha1_hex(bufptr + 5, parent) < 0)
+ if (
tail <= bufptr + 45 ||
get_sha1_hex(bufptr + 5, parent) < 0)
return error("bad tree pointer in commit %s",
sha1_to_hex(item->object.sha1));
item->tree = lookup_tree(parent);
return error("bad tree pointer in commit %s",
sha1_to_hex(item->object.sha1));
item->tree = lookup_tree(parent);
@@
-257,10
+259,12
@@
int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size)
pptr = &item->parents;
graft = lookup_commit_graft(item->object.sha1);
pptr = &item->parents;
graft = lookup_commit_graft(item->object.sha1);
- while (!memcmp(bufptr, "parent ", 7)) {
+ while (
bufptr + 48 < tail &&
!memcmp(bufptr, "parent ", 7)) {
struct commit *new_parent;
struct commit *new_parent;
- if (get_sha1_hex(bufptr + 7, parent) || bufptr[47] != '\n')
+ if (tail <= bufptr + 48 ||
+ get_sha1_hex(bufptr + 7, parent) ||
+ bufptr[47] != '\n')
return error("bad parents in commit %s", sha1_to_hex(item->object.sha1));
bufptr += 48;
if (graft)
return error("bad parents in commit %s", sha1_to_hex(item->object.sha1));
bufptr += 48;
if (graft)