Got rid of some fuzz.
[rsync/rsync-patches.git] / daemon-glob.patch
CommitLineData
1cd28ec2
WD
1After applying this patch and running configure, you MUST run this
2command before "make":
3
4 make proto
5
c706d729
WD
6--- clientserver.c 5 Jun 2004 19:59:03 -0000 1.123
7+++ clientserver.c 5 Jun 2004 20:38:15 -0000
8@@ -207,7 +207,8 @@ int start_inband_exchange(char *user, ch
9 static int rsync_module(int f_in, int f_out, int i)
10 {
11 int argc = 0;
12- char *argv[MAX_ARGS];
13+ int maxargs;
14+ char **argv;
15 char **argp;
16 char line[MAXPATHLEN];
17 uid_t uid = (uid_t)-2; /* canonically "nobody" */
18@@ -385,6 +386,9 @@ static int rsync_module(int f_in, int f_
19
20 io_printf(f_out, "@RSYNCD: OK\n");
21
22+ maxargs = MAX_ARGS;
23+ if (!(argv = new_array(char *, maxargs)))
24+ out_of_memory("rsync_module");
25 argv[argc++] = "rsyncd";
26
27 while (1) {
28@@ -396,23 +400,25 @@ static int rsync_module(int f_in, int f_
29
30 p = line;
31
32+ if (argc == maxargs) {
33+ maxargs += MAX_ARGS;
34+ if (!(argv = realloc_array(argv, char *, maxargs)))
35+ out_of_memory("rsync_module");
36+ }
37 if (!(argv[argc] = strdup(p)))
38- return -1;
39+ out_of_memory("rsync_module");
40
41 if (start_glob) {
42 if (start_glob == 1) {
43 request = strdup(p);
44 start_glob++;
45 }
46- glob_expand(name, argv, &argc, MAX_ARGS);
47+ glob_expand(name, &argv, &argc, &maxargs);
48 } else
49 argc++;
50
51 if (strcmp(line, ".") == 0)
52 start_glob = 1;
53-
54- if (argc == MAX_ARGS)
55- return -1;
56 }
57
58 argp = argv;
c706d729
WD
59--- util.c 5 Jun 2004 20:26:56 -0000 1.148
60+++ util.c 5 Jun 2004 20:38:16 -0000
61@@ -495,12 +495,20 @@ static int exclude_server_path(char *arg
62 return 0;
63 }
64
65-static void glob_expand_one(char *s, char **argv, int *argc_ptr, int maxargs)
66+static void glob_expand_one(char *s, char ***argv_ptr, int *argc_ptr,
67+ int *maxargs_ptr)
68 {
69+ char **argv = *argv_ptr;
70 int argc = *argc_ptr;
71+ int maxargs = *maxargs_ptr;
72 #if !(defined(HAVE_GLOB) && defined(HAVE_GLOB_H))
73- if (maxargs <= argc)
74- return;
75+ if (argc == maxargs) {
76+ maxargs += MAX_ARGS;
77+ if (!(argv = realloc_array(argv, char *, maxargs)))
78+ out_of_memory("glob_expand_one");
79+ *argv_ptr = argv;
80+ *maxargs_ptr = maxargs;
81+ }
82 if (!*s)
83 s = ".";
84 s = argv[argc++] = strdup(s);
85@@ -521,12 +529,17 @@ static void glob_expand_one(char *s, cha
86 memset(&globbuf, 0, sizeof globbuf);
87 if (!exclude_server_path(s))
88 glob(s, 0, NULL, &globbuf);
89+ if (MAX((int)globbuf.gl_pathc, 1) > maxargs - argc) {
90+ maxargs += globbuf.gl_pathc + MAX_ARGS;
91+ if (!(argv = realloc_array(argv, char *, maxargs)))
92+ out_of_memory("glob_expand_one");
93+ *argv_ptr = argv;
94+ *maxargs_ptr = maxargs;
95+ }
96 if (globbuf.gl_pathc == 0)
97 argv[argc++] = s;
98 else {
99 int j = globbuf.gl_pathc;
100- if (j > maxargs - argc)
101- j = maxargs - argc;
102 free(s);
103 for (i = 0; i < j; i++) {
104 if (!(argv[argc++] = strdup(globbuf.gl_pathv[i])))
105@@ -539,9 +552,9 @@ static void glob_expand_one(char *s, cha
106 }
107
108 /* This routine is only used in daemon mode. */
109-void glob_expand(char *base1, char **argv, int *argc_ptr, int maxargs)
110+void glob_expand(char *base1, char ***argv_ptr, int *argc_ptr, int *maxargs_ptr)
111 {
112- char *s = argv[*argc_ptr];
113+ char *s = (*argv_ptr)[*argc_ptr];
114 char *p, *q;
115 char *base = base1;
116 int base_len = strlen(base);
117@@ -562,7 +575,7 @@ void glob_expand(char *base1, char **arg
118 for (q = s; *q; q = p + base_len) {
119 if ((p = strstr(q, base)) != NULL)
120 *p = '\0'; /* split it at this point */
121- glob_expand_one(q, argv, argc_ptr, maxargs);
122+ glob_expand_one(q, argv_ptr, argc_ptr, maxargs_ptr);
123 if (!p)
124 break;
125 }