From: Junio C Hamano <gitster@pobox.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Pierre Habouzit <madcoder@debian.org>,
spearce@spearce.org, Git Mailing List <git@vger.kernel.org>
Subject: Re: [PATCH] Fix segfault in diff-delta.c when FLEX_ARRAY is 1
Date: Tue, 18 Dec 2007 01:07:01 -0800 [thread overview]
Message-ID: <7vwsrc1idm.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <alpine.LFD.0.9999.0712172146070.21557@woody.linux-foundation.org> (Linus Torvalds's message of "Mon, 17 Dec 2007 22:12:03 -0800 (PST)")
Linus Torvalds <torvalds@linux-foundation.org> writes:
> But there's a few that aren't obviously allocations (this is a list done
> with grep and sparse, I didn't look at whether the values used are then
> all allocation-related):
>
> - builtin-blame.c:128 memset(o, 0, sizeof(*o));
This is harmless and in fact unnecessary clearing, immediately before
calling free(3).
> - diff-delta.c:250 memsize = sizeof(*index)
I haven't studied this codepath.
> - object-refs.c:23 size_t size = sizeof(*refs) + count*sizeof(struct object *);
Overallocation to have at least "count" pointers to "struct object".
> - object-refs.c:61 size_t size = sizeof(*refs) + j*sizeof(struct object *);
Ditto for "j" pointers.
> - attr.c:220 sizeof(*res) +
Overallocation to have at least "num_attr" instances of "struct
attr_state" (plus name string if needed, which is stored using location
past state[num_attr]).
> - remote.c:467 memset(ret, 0, sizeof(struct ref) + namelen);
Clearing an arena that was overallocated to have at least namelen
elements of char[] on the line immediately before this, with matching
size. All callers pass namelen = strlen(name) + 1 so we are Ok even
when FLEX_ARRAY gives no extra space.
> - remote.c:474 memcpy(ret, ref, sizeof(struct ref) + strlen(ref->name) + 1);
Ditto.
> - transport.c:491 memset(ref, 0, sizeof(struct ref));
A line above overallocates to have enough room for strlen(ref_name) plus
terminating NUL, and after this lines clears the non-flex part, name is
copied. So this overclears a bit, but is harmless.
> diff --git a/unpack-trees.c b/unpack-trees.c
> index e9eb795..aa2513e 100644
> --- a/unpack-trees.c
> +++ b/unpack-trees.c
> @@ -590,7 +590,7 @@ static int merged_entry(struct cache_entry *merge, struct cache_entry *old,
> * a match.
> */
> if (same(old, merge)) {
> - *merge = *old;
> + memcpy(merge, old, offsetof(struct cache_entry, name));
> } else {
> verify_uptodate(old, o);
> invalidate_ce_path(old);
Portability of offsetof() is slightly worrisome, but giving a
compatibility macro is trivial if this turns out to be problematic for
some people.
next prev parent reply other threads:[~2007-12-18 9:07 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-18 1:39 [PATCH] Fix segfault in diff-delta.c when FLEX_ARRAY is 1 Pierre Habouzit
2007-12-18 1:44 ` Pierre Habouzit
2007-12-18 4:46 ` Linus Torvalds
2007-12-18 6:12 ` Linus Torvalds
2007-12-18 9:07 ` Junio C Hamano [this message]
2007-12-18 11:15 ` David Kastrup
2007-12-18 14:46 ` Nicolas Pitre
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=7vwsrc1idm.fsf@gitster.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=madcoder@debian.org \
--cc=spearce@spearce.org \
--cc=torvalds@linux-foundation.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.