From: mhagger@alum.mit.edu
To: Junio C Hamano <gitster@pobox.com>
Cc: Nguyen Thai Ngoc Duy <pclouds@gmail.com>,
git@vger.kernel.org, Michael Haggerty <mhagger@alum.mit.edu>
Subject: [PATCH v2 4/4] cmd_fetch_pack(): respect constness of argv parameter
Date: Mon, 21 May 2012 09:59:59 +0200 [thread overview]
Message-ID: <1337587199-21099-5-git-send-email-mhagger@alum.mit.edu> (raw)
In-Reply-To: <1337587199-21099-1-git-send-email-mhagger@alum.mit.edu>
From: Michael Haggerty <mhagger@alum.mit.edu>
The old code cast away the constness of the strings passed to the
function in argument argv[], which could result in their being
modified by filter_refs(). Fix by copying reference names from argv
and putting them into our own array (similarly to how refnames passed
to stdin were already handled).
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
This change results in heads being left set to NULL if nr_heads==0,
but all of the code paths are OK with this.
builtin/fetch-pack.c | 23 ++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)
diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c
index 96849a4..7ad9e54 100644
--- a/builtin/fetch-pack.c
+++ b/builtin/fetch-pack.c
@@ -899,10 +899,11 @@ static void fetch_pack_setup(void)
int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
{
- int i, ret, nr_heads;
+ int i, ret;
struct ref *ref = NULL;
const char *dest = NULL;
- char **heads;
+ int alloc_heads = 0, nr_heads = 0;
+ char **heads = NULL;
int fd[2];
char *pack_lockfile = NULL;
char **pack_lockfile_ptr = NULL;
@@ -910,7 +911,6 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
packet_trace_identity("fetch-pack");
- heads = NULL;
for (i = 1; i < argc && *argv[i] == '-'; i++) {
const char *arg = argv[i];
@@ -976,17 +976,14 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
else
usage(fetch_pack_usage);
- heads = (char **)(argv + i);
- nr_heads = argc - i;
-
+ /*
+ * Copy refs from cmdline to growable list, then append any
+ * refs from the standard input:
+ */
+ ALLOC_GROW(heads, argc - i, alloc_heads);
+ for (; i < argc; i++)
+ heads[nr_heads++] = xstrdup(argv[i]);
if (args.stdin_refs) {
- /*
- * Copy refs from cmdline to new growable list, then
- * append the refs from the standard input.
- */
- int alloc_heads = nr_heads;
- int size = nr_heads * sizeof(*heads);
- heads = memcpy(xmalloc(size), heads, size);
if (args.stateless_rpc) {
/* in stateless RPC mode we use pkt-line to read
* from stdin, until we get a flush packet
--
1.7.10
prev parent reply other threads:[~2012-05-21 8:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-21 7:59 [PATCH v2 0/4] Fix some constness errors in fetch-pack mhagger
2012-05-21 7:59 ` [PATCH v2 1/4] cmd_fetch_pack(): declare dest to be const mhagger
2012-05-21 7:59 ` [PATCH v2 2/4] cmd_fetch_pack(): handle non-option arguments outside of the loop mhagger
2012-05-21 7:59 ` [PATCH v2 3/4] cmd_fetch_pack(): combine the loop termination conditions mhagger
2012-05-21 7:59 ` mhagger [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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1337587199-21099-5-git-send-email-mhagger@alum.mit.edu \
--to=mhagger@alum.mit.edu \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=pclouds@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).