git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org, "René Scharfe" <rene.scharfe@lsrfire.ath.cx>,
	"Thomas Rast" <trast@student.ethz.ch>,
	"Junio C Hamano" <gitster@pobox.com>
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH] parse_tag_buffer(): avoid out of bound access
Date: Fri, 18 Feb 2011 19:49:32 +0700	[thread overview]
Message-ID: <1298033372-29069-1-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <4D5D17F7.4010003@lsrfire.ath.cx>

There is a check (size < 64) at the beginning of the function, but
that only covers object+type lines. Code for parsing "tag" and
"tagger" may access outside buffer. Fix it.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 On Thu, Feb 17, 2011 at 7:43 PM, René Scharfe <rene.scharfe@lsrfire.ath.cx> wrote:
 > memchr() won't notice if a negative value has been passed as third parameter
 > because its type is size_t, which is unsigned.  Negative values are
 > converted to big positive ones..

 I did not notice that. Fixed commit message.

 tag.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/tag.c b/tag.c
index ecf7c1e..7d38cc0 100644
--- a/tag.c
+++ b/tag.c
@@ -97,7 +97,9 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
 		item->tagged = NULL;
 	}
 
-	if (prefixcmp(bufptr, "tag "))
+	if (bufptr + 4 < tail && !prefixcmp(bufptr, "tag "))
+		; 		/* good */
+	else
 		return -1;
 	bufptr += 4;
 	nl = memchr(bufptr, '\n', tail - bufptr);
@@ -106,7 +108,7 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
 	item->tag = xmemdupz(bufptr, nl - bufptr);
 	bufptr = nl + 1;
 
-	if (!prefixcmp(bufptr, "tagger "))
+	if (bufptr + 7 < tail && !prefixcmp(bufptr, "tagger "))
 		item->date = parse_tag_date(bufptr, tail);
 	else
 		item->date = 0;
-- 
1.7.4.74.g639db

      reply	other threads:[~2011-02-18 12:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-05 10:52 [PATCH 1/2] Add const to parse_{commit,tag}_buffer() Nguyễn Thái Ngọc Duy
2011-02-05 10:52 ` [PATCH 2/2] Make hash-object more robust against malformed objects Nguyễn Thái Ngọc Duy
2011-02-12 11:42   ` Thomas Rast
2011-02-12 14:47     ` Nguyen Thai Ngoc Duy
2011-02-14 13:02       ` [PATCH] parse_tag_buffer(): do not prefixcmp() out of range Nguyễn Thái Ngọc Duy
2011-02-15 21:18         ` Junio C Hamano
2011-02-16  3:39           ` Nguyen Thai Ngoc Duy
2011-02-17 12:43             ` René Scharfe
2011-02-18 12:49               ` Nguyễn Thái Ngọc Duy [this message]

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=1298033372-29069-1-git-send-email-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=rene.scharfe@lsrfire.ath.cx \
    --cc=trast@student.ethz.ch \
    /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).