From: Jeff King <peff@peff.net>
To: Thomas Rast <trast@student.ethz.ch>
Cc: Franck Bui-Huu <vagabon.xyz@gmail.com>,
Erik Faye-Lund <kusmabite@gmail.com>,
git@vger.kernel.org, gitster@pobox.com, j6t@kdbg.org,
rene.scharfe@lsrfire.ath.cx
Subject: Re: [PATCH v4 3/3] upload-archive: use start_command instead of fork
Date: Tue, 15 Nov 2011 12:37:15 -0500 [thread overview]
Message-ID: <20111115173715.GA4478@sigill.intra.peff.net> (raw)
In-Reply-To: <201111151311.46832.trast@student.ethz.ch>
On Tue, Nov 15, 2011 at 01:11:46PM +0100, Thomas Rast wrote:
> But after a closer look I think this patch just prodded it enough to
> unearth long-existing undefined behaviour: prepare_argv() summarizes
> to something like
>
> static void prepare_argv(const char **sent_argv, const char **argv)
> {
> char *p, buf[4096];
>
> for (p = buf;;) {
> len = packet_read_line(0, p, (buf + sizeof buf) - p);
> /* ... p always points into buf ... */
> sent_argv[sent_argc++] = p;
> p += len;
> *p++ = 0;
> }
> sent_argv[sent_argc] = NULL;
> }
>
> The code appears to have looked like this ever since the addition of
> that file back in 39345a2 (Add git-upload-archive, 2006-09-07). So
> the elements of sent_argv have apparently always pointed into the
> stack-allocated 'buf'.
Oh, yikes. That is definitely the problem, but it does come from
c09cd77e. The prepare_argv function used to be "run_upload_archive", and
it would prepare argv on the stack, call into write_archive with it, and
then return; nobody else cares about the value afterwards.
Erik's patch converts it into a function that writes the new argv into a
parameter and returns, and the now-invalid stack-allocated memory is
used by the calling function.
> A quick band-aid would be to heap-allocate it instead:
That works. An even shorter band-aid is to mark it as "static".
I think the code would be more readable if it just used the new
argv_array.
Junio, this bug is in 1.7.8-rc*. Do you want the one-liner fix for the
release, or the nicer fix?
-Peff
next prev parent reply other threads:[~2011-11-15 17:37 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-24 16:02 [PATCH v4 0/3] port upload-archive to Windows Erik Faye-Lund
2011-10-24 16:02 ` [PATCH v4 1/3] mingw: move poll out of sys-folder Erik Faye-Lund
2011-10-24 16:02 ` [PATCH v4 2/3] compat/win32/poll.c: upgrade from upstream Erik Faye-Lund
2011-10-24 16:02 ` [PATCH v4 3/3] upload-archive: use start_command instead of fork Erik Faye-Lund
2011-10-24 22:39 ` Jeff King
2011-11-15 10:22 ` Thomas Rast
2011-11-15 10:28 ` Jeff King
2011-11-15 12:11 ` Thomas Rast
2011-11-15 17:37 ` Jeff King [this message]
2011-11-15 17:44 ` Erik Faye-Lund
2011-11-15 18:18 ` Jeff King
2011-11-15 18:59 ` Junio C Hamano
2011-11-15 19:18 ` Jeff King
2011-11-15 19:46 ` [PATCH 1/2] upload-archive: drop extra argument to prepare_argv Jeff King
2011-11-15 19:49 ` [PATCH] upload-archive: use argv_array for sent parameters Jeff King
2011-11-15 21:30 ` Jeff King
2011-11-15 18:53 ` [PATCH v4 3/3] upload-archive: use start_command instead of fork Andreas Schwab
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=20111115173715.GA4478@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=j6t@kdbg.org \
--cc=kusmabite@gmail.com \
--cc=rene.scharfe@lsrfire.ath.cx \
--cc=trast@student.ethz.ch \
--cc=vagabon.xyz@gmail.com \
/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).