From: Junio C Hamano <gitster@pobox.com>
To: Martin Koegler <mkoegler@auto.tuwien.ac.at>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] tree-walk: don't parse incorrect entries
Date: Sat, 05 Jan 2008 12:50:28 -0800 [thread overview]
Message-ID: <7v1w8w80a3.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <1199555243534-git-send-email-mkoegler@auto.tuwien.ac.at> (Martin Koegler's message of "Sat, 5 Jan 2008 18:47:23 +0100")
Martin Koegler <mkoegler@auto.tuwien.ac.at> writes:
> The current code can access memory outside of the tree
> buffer in the case of malformed tree entries.
>
> This patch prevent this by:
> * The rest of the buffer must be at least 24 bytes
> (at least 1 byte mode, 1 blank, at least one byte path name,
> 1 zero, 20 bytes sha1).
Good ("zero" in this context is better spelled as "NUL").
> * Check that the last zero (21 bytes before the end) is present.
> This ensurse, that strlen and get_mode stay within the buffer.
Good (ditto).
> * The mode may not be empty. We have only to reject a blank at the begin,
> as the rest is handled by if (c < '0' || c > '7').
I initially thought this was slightly iffy as tree objects were
written with padding for mode bits, but that was padding with
zero ('0') to the left and not with SP, so it is a good change,
I think (I am saying this primarily so that others can say "you
are wrong, there are valid old trees with SP there" to stop me).
> * The blank is ensured by get_mode.
Ok.
> * The start of the path may not be after the last zero (21 bytes before the end).
How can that be possible?
- you know end points at NUL and buf < end;
- get_mode() starts scanning from buf, stops at the first SP if
returns a non NULL pointer; anything non octal digit before
it sees that SP results in a NULL return;
- the return value of get_mode() is the beginning of the path.
The second point above means when get_mode() scans buf, it would
never go beyond end which you already made sure is NUL (which is
not SP and not an octal digit). If it hits end, you would get NULL
pointer back, wouldn't you?
Rejecting an empty path may be sensible (i.e. checking "!*path"
instead), though.
next prev parent reply other threads:[~2008-01-05 20:51 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-05 17:47 [PATCH] tree-walk: don't parse incorrect entries Martin Koegler
2008-01-05 20:50 ` Junio C Hamano [this message]
2008-01-06 17:23 ` Martin Koegler
-- strict thread matches above, loose matches on Subject: below --
2008-01-06 17:21 Martin Koegler
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=7v1w8w80a3.fsf@gitster.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=mkoegler@auto.tuwien.ac.at \
/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).