From: Junio C Hamano <junio@pobox.com>
To: drafnel@gmail.com
Cc: git@vger.kernel.org, Brandon Casey <casey@nrlssc.navy.mil>
Subject: Re: [PATCH 1/5] mktag.c: adjust verify_tag parameters
Date: Sun, 11 May 2008 11:39:46 -0700 [thread overview]
Message-ID: <7vmymw3cst.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: 3712867.1210299524581.JavaMail.teamon@b301.teamon.com
drafnel@gmail.com writes:
> From: Brandon Casey <casey@nrlssc.navy.mil>
>
> The size parameter should be a size_t since it is a string length.
Correct.
> There is no reason that the buffer argument should not be constant except
> for the nul termination that is performed in the first few lines of this
> function. This is not necessary, since a valid c string must always be
> nul terminated and we can check whether we have exceeded the caller's
> size parameter at the end of parsing the buffer.
Wait a minute. The point of passing a stringlet as a tuple of <pointer to
the beginning, length> is that you may not have a valid C string to begin
with, isn't it? We shouldn't be assuming that reading past the given size
is Ok --- you may not be lucky enough to have any NUL byte after the given
string before you hit the page boundary and encounter unmapped page.
The generic-looking argument you made is bogus, but for this particular
code it is true, as the parameter you are passing to the function is
prepared by strbuf_read() which gives you a NUL terminated buffer.
So the code is correct -- justification is not.
> Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
> ---
> mktag.c | 11 ++++++++---
> 1 files changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/mktag.c b/mktag.c
> index 0b34341..5489ad6 100644
> --- a/mktag.c
> +++ b/mktag.c
> @@ -39,7 +39,7 @@ static int verify_object(unsigned char *sha1, const char *expected_type)
> #define PD_FMT "%td"
> #endif
>
> -static int verify_tag(char *buffer, unsigned long size)
> +static int verify_tag(const char *buffer, size_t size)
> {
> int typelen;
> char type[20];
> @@ -50,8 +50,6 @@ static int verify_tag(char *buffer, unsigned long size)
> if (size < 84)
> return error("wanna fool me ? you obviously got the size wrong !");
>
> - buffer[size] = 0;
> -
> /* Verify object line */
> object = buffer;
> if (memcmp(object, "object ", 7))
> @@ -145,6 +143,13 @@ static int verify_tag(char *buffer, unsigned long size)
> return error("char" PD_FMT ": trailing garbage in tag header",
> tagger_line - buffer);
>
> + /*
> + * Make sure we haven't advanced past what the caller said the
> + * buffer size was.
> + */
> + if (tagger_line - buffer >= size)
> + return error("char" PD_FMT ": tag truncated", size);
> +
> /* The actual stuff afterwards we don't care about.. */
> return 0;
> }
> --
> 1.5.5.67.g9a49
next prev parent reply other threads:[~2008-05-11 18:40 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1210299589-10448-1-git-send-email-drafnel@example.com>
2008-05-09 2:19 ` [PATCH 1/5] mktag.c: adjust verify_tag parameters drafnel
2008-05-11 18:39 ` Junio C Hamano [this message]
2008-05-12 15:43 ` Brandon Casey
[not found] ` <1210299589-10448-2-git-send-email-drafnel@example.com>
2008-05-09 2:19 ` [PATCH 2/5] Make mktag a builtin drafnel
2008-05-11 17:28 ` Junio C Hamano
2008-05-11 17:36 ` Junio C Hamano
2008-05-12 15:09 ` Brandon Casey
2008-05-12 17:04 ` Johannes Schindelin
2008-05-12 17:32 ` Brandon Casey
2008-05-12 18:41 ` Junio C Hamano
[not found] ` <1210299589-10448-3-git-send-email-drafnel@example.com>
2008-05-09 2:19 ` [PATCH 3/5] mktag.c: rename verify_tag to verify_tag_buffer drafnel
[not found] ` <1210299589-10448-4-git-send-email-drafnel@example.com>
2008-05-09 2:19 ` [PATCH 4/5] mktag.c: consolidate tag functions by merging mktag.c into builtin-tag.c drafnel
[not found] ` <1210299589-10448-5-git-send-email-drafnel@example.com>
2008-05-09 2:19 ` [PATCH 5/5] git-tag: call verify_tag_buffer to validate the generated tag object drafnel
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7vmymw3cst.fsf@gitster.siamese.dyndns.org \
--to=junio@pobox.com \
--cc=casey@nrlssc.navy.mil \
--cc=drafnel@gmail.com \
--cc=git@vger.kernel.org \
/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.
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 NNTP newsgroup(s).