aboutsummaryrefslogtreecommitdiff
path: root/builtin/fetch-pack.c
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2012-05-21 09:59:59 +0200
committerJunio C Hamano <gitster@pobox.com>2012-05-22 12:57:20 -0700
commit57e6fc69588ea5e1b6a151d60f2cf9fa636251c1 (patch)
tree0b3c4dff7120c7429f3a99f1a714f8343ff139af /builtin/fetch-pack.c
parentff22ff9909a09d775c740f31443f96edd5b5e006 (diff)
downloadgit-57e6fc69588ea5e1b6a151d60f2cf9fa636251c1.tar.gz
git-57e6fc69588ea5e1b6a151d60f2cf9fa636251c1.tar.xz
cmd_fetch_pack(): respect constness of argv parameter
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/fetch-pack.c')
-rw-r--r--builtin/fetch-pack.c23
1 files changed, 10 insertions, 13 deletions
diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c
index dc4b1dcec..80e72df49 100644
--- a/builtin/fetch-pack.c
+++ b/builtin/fetch-pack.c
@@ -898,10 +898,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;
@@ -909,7 +910,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];
@@ -975,17 +975,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