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>
Michael Haggerty committed
May 21, 2012 at 09:59 UTC
57e6fc69588ea5e1b6a151d60f2cf9fa636251c1
1 file changed
+10
-13
builtin/fetch-pack.c
+10
-13
@@ -898,10 +898,11 @@ static void fetch_pack_setup(void)
898
899
int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
900
{
901
- int i, ret, nr_heads;
901
+ int i, ret;
902
struct ref *ref = NULL;
903
const char *dest = NULL;
904
- char **heads;
904
+ int alloc_heads = 0, nr_heads = 0;
905
+ char **heads = NULL;
906
int fd[2];
907
char *pack_lockfile = NULL;
908
char **pack_lockfile_ptr = NULL;
@@ -909,7 +910,6 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
910
911
packet_trace_identity("fetch-pack");
912
912
- heads = NULL;
913
for (i = 1; i < argc && *argv[i] == '-'; i++) {
914
const char *arg = argv[i];
915
@@ -975,17 +975,14 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
975
else
976
usage(fetch_pack_usage);
977
978
- heads = (char **)(argv + i);
979
- nr_heads = argc - i;
980
-
978
+ /*
979
+ * Copy refs from cmdline to growable list, then append any
980
+ * refs from the standard input:
981
+ */
982
+ ALLOC_GROW(heads, argc - i, alloc_heads);
983
+ for (; i < argc; i++)
984
+ heads[nr_heads++] = xstrdup(argv[i]);
985
if (args.stdin_refs) {
982
- /*
983
- * Copy refs from cmdline to new growable list, then
984
- * append the refs from the standard input.
985
- */
986
- int alloc_heads = nr_heads;
987
- int size = nr_heads * sizeof(*heads);
988
- heads = memcpy(xmalloc(size), heads, size);
986
if (args.stateless_rpc) {
987
/* in stateless RPC mode we use pkt-line to read
988
* from stdin, until we get a flush packet