(list_file,print_dir,print_file): Use mkfullname. Fixes [bug #15144].
Showing
1 changed file
with
36 additions
and
17 deletions
... | @@ -194,6 +194,27 @@ inode_list_lookup (struct inode_list *list, struct stat *st) | ... | @@ -194,6 +194,27 @@ inode_list_lookup (struct inode_list *list, struct stat *st) |
194 | return 0; | 194 | return 0; |
195 | } | 195 | } |
196 | 196 | ||
197 | static char * | ||
198 | mkfullname (const char *dir, const char *name, const char *delim) | ||
199 | { | ||
200 | char *p; | ||
201 | int dlen = strlen (dir); | ||
202 | |||
203 | if (dlen == 0) | ||
204 | return strdup (name); | ||
205 | |||
206 | if (dir[dlen-1] == delim[0]) | ||
207 | dlen--; | ||
208 | |||
209 | p = malloc (dlen + 1 + strlen (name) + 1); | ||
210 | if (p) | ||
211 | { | ||
212 | memcpy (p, dir, dlen); | ||
213 | p[dlen] = '/'; | ||
214 | strcpy (p + dlen + 1, name); | ||
215 | } | ||
216 | return p; | ||
217 | } | ||
197 | 218 | ||
198 | /* Recusively calling the files. */ | 219 | /* Recusively calling the files. */ |
199 | static void | 220 | static void |
... | @@ -204,6 +225,9 @@ list_file (const char *cwd, const char *ref, const char *pattern, | ... | @@ -204,6 +225,9 @@ list_file (const char *cwd, const char *ref, const char *pattern, |
204 | struct dirent *dp; | 225 | struct dirent *dp; |
205 | char *next; | 226 | char *next; |
206 | 227 | ||
228 | if (!cwd || !ref) | ||
229 | return; | ||
230 | |||
207 | /* Shortcut no wildcards. */ | 231 | /* Shortcut no wildcards. */ |
208 | if (*pattern == '\0' || !strpbrk (pattern, "%*")) | 232 | if (*pattern == '\0' || !strpbrk (pattern, "%*")) |
209 | { | 233 | { |
... | @@ -266,12 +290,8 @@ list_file (const char *cwd, const char *ref, const char *pattern, | ... | @@ -266,12 +290,8 @@ list_file (const char *cwd, const char *ref, const char *pattern, |
266 | inode_rec.inode = st.st_ino; | 290 | inode_rec.inode = st.st_ino; |
267 | inode_rec.dev = st.st_dev; | 291 | inode_rec.dev = st.st_dev; |
268 | inode_rec.next = inode_list; | 292 | inode_rec.next = inode_list; |
269 | rf = calloc (strlen (ref) + strlen (delim) + | 293 | rf = mkfullname (ref, entry, delim); |
270 | strlen (entry) + 1, 1); | 294 | cd = mkfullname (cwd, entry, delim); |
271 | sprintf (rf, "%s%s%s", ref, delim, entry); | ||
272 | cd = calloc (strlen (cwd) + strlen (delim) + | ||
273 | strlen (entry) + 1, 1); | ||
274 | sprintf (cd, "%s%s%s", cwd, delim, entry); | ||
275 | list_file (cd, rf, (next) ? next : pattern, | 295 | list_file (cd, rf, (next) ? next : pattern, |
276 | delim, &inode_rec); | 296 | delim, &inode_rec); |
277 | free (rf); | 297 | free (rf); |
... | @@ -298,15 +318,16 @@ list_file (const char *cwd, const char *ref, const char *pattern, | ... | @@ -298,15 +318,16 @@ list_file (const char *cwd, const char *ref, const char *pattern, |
298 | static void | 318 | static void |
299 | print_file (const char *ref, const char *file, const char *delim) | 319 | print_file (const char *ref, const char *file, const char *delim) |
300 | { | 320 | { |
321 | char *name = mkfullname (ref, file, delim); | ||
301 | if (strpbrk (file, "\"{}")) | 322 | if (strpbrk (file, "\"{}")) |
302 | { | 323 | { |
303 | util_out (RESP_NONE, "LIST (\\NoInferiors) \"%s\" {%d}", delim, | 324 | util_out (RESP_NONE, "LIST (\\NoInferiors) \"%s\" {%d}", delim, |
304 | strlen (ref) + strlen ((*ref) ? delim : "") + strlen (file)); | 325 | strlen (name)); |
305 | util_send ("%s%s%s\r\n", ref, (*ref) ? delim : "", file); | 326 | util_send ("%s\r\n", name); |
306 | } | 327 | } |
307 | else | 328 | else |
308 | util_out (RESP_NONE, "LIST (\\NoInferiors) \"%s\" %s%s%s", delim, | 329 | util_out (RESP_NONE, "LIST (\\NoInferiors) \"%s\" %s", delim, name); |
309 | ref, (*ref) ? delim : "", file); | 330 | free (name); |
310 | } | 331 | } |
311 | 332 | ||
312 | /* Make sure that the file name does not contain any undesirable | 333 | /* Make sure that the file name does not contain any undesirable |
... | @@ -314,18 +335,16 @@ print_file (const char *ref, const char *file, const char *delim) | ... | @@ -314,18 +335,16 @@ print_file (const char *ref, const char *file, const char *delim) |
314 | static void | 335 | static void |
315 | print_dir (const char *ref, const char *file, const char *delim) | 336 | print_dir (const char *ref, const char *file, const char *delim) |
316 | { | 337 | { |
338 | char *name = mkfullname (ref, file, delim); | ||
317 | if (strpbrk (file, "\"{}")) | 339 | if (strpbrk (file, "\"{}")) |
318 | { | 340 | { |
319 | util_out (RESP_NONE, "LIST (\\NoSelect) \"%s\" {%d}", delim, | 341 | util_out (RESP_NONE, "LIST (\\NoSelect) \"%s\" {%d}", delim, |
320 | strlen (ref) + strlen ((*ref) ? delim : "") + strlen (file)); | 342 | strlen (name)); |
321 | util_send ("%s%s%s\r\n", ref, (*ref) ? delim : "", file); | 343 | util_send ("%s\r\n", name); |
322 | } | 344 | } |
323 | else if (*file) | ||
324 | util_out (RESP_NONE, "LIST (\\NoSelect) \"%s\" %s%s%s", delim, | ||
325 | ref, (*ref) ? delim : "", file); | ||
326 | else | 345 | else |
327 | util_out (RESP_NONE, "LIST (\\NoSelect) \"%s\" \"%s%s\"", delim, | 346 | util_out (RESP_NONE, "LIST (\\NoSelect) \"%s\" %s", delim, name); |
328 | ref, (*ref) ? delim : ""); | 347 | free (name); |
329 | } | 348 | } |
330 | 349 | ||
331 | /* Calls the imap_matcher if a match found out the attribute. */ | 350 | /* Calls the imap_matcher if a match found out the attribute. */ | ... | ... |
-
Please register or sign in to post a comment