(mh_expand_name): Make sure the returned value can safely be freed.
Showing
1 changed file
with
12 additions
and
16 deletions
... | @@ -404,39 +404,35 @@ mh_get_dir () | ... | @@ -404,39 +404,35 @@ mh_get_dir () |
404 | char * | 404 | char * |
405 | mh_expand_name (const char *base, const char *name, int is_folder) | 405 | mh_expand_name (const char *base, const char *name, int is_folder) |
406 | { | 406 | { |
407 | char *tmp = NULL; | ||
408 | char *p = NULL; | 407 | char *p = NULL; |
409 | char *namep; | 408 | char *namep = NULL; |
410 | 409 | ||
411 | tmp = mu_tilde_expansion (name, "/", NULL); | 410 | namep = mu_tilde_expansion (name, "/", NULL); |
412 | if (tmp[0] == '+') | 411 | if (namep[0] == '+') |
413 | namep = tmp + 1; | 412 | memmove (namep, namep + 1, strlen (namep)); /* copy null byte as well */ |
414 | else if (strncmp (tmp, "../", 3) == 0 || strncmp (tmp, "./", 2) == 0) | 413 | else if (strncmp (namep, "../", 3) == 0 || strncmp (namep, "./", 2) == 0) |
415 | { | 414 | { |
416 | char *cwd = mu_getcwd (); | 415 | char *cwd = mu_getcwd (); |
417 | asprintf (&namep, "%s/%s", cwd, tmp); | 416 | char *tmp = NULL; |
417 | asprintf (&tmp, "%s/%s", cwd, namep); | ||
418 | free (cwd); | 418 | free (cwd); |
419 | free (tmp); | 419 | free (namep); |
420 | tmp = NULL; | ||
421 | } | ||
422 | else | ||
423 | namep = tmp; | 420 | namep = tmp; |
421 | } | ||
424 | 422 | ||
425 | if (!base) | ||
426 | base = mu_folder_directory (); | ||
427 | if (is_folder) | 423 | if (is_folder) |
428 | { | 424 | { |
429 | if (namep[0] == '/') | 425 | if (namep[0] == '/') |
430 | asprintf (&p, "mh:%s", namep); | 426 | asprintf (&p, "mh:%s", namep); |
431 | else | 427 | else |
432 | asprintf (&p, "mh:%s/%s", base, namep); | 428 | asprintf (&p, "mh:%s/%s", base ? base : mu_folder_directory (), namep); |
433 | } | 429 | } |
434 | else if (namep[0] != '/') | 430 | else if (namep[0] != '/') |
435 | asprintf (&p, "%s/%s", base, namep); | 431 | asprintf (&p, "%s/%s", base ? base : mu_folder_directory (), namep); |
436 | else | 432 | else |
437 | return namep; | 433 | return namep; |
438 | 434 | ||
439 | free (tmp); | 435 | free (namep); |
440 | return p; | 436 | return p; |
441 | } | 437 | } |
442 | 438 | ... | ... |
-
Please register or sign in to post a comment