Commit d3759d84 d3759d840f37fa6a56fcbe57b7bce8883f210593 by Sergey Poznyakoff

Use mu_make_file_name where necessary.

* comsat/action.c (run_user_action): Use mu_make_file_name.
* imap4d/lsub.c (imap4d_lsub): Likewise.
* imap4d/subscribe.c (imap4d_subscribe): Likewise.
* imap4d/unsubscribe.c (imap4d_unsubscribe): Likewise.
* libmailutils/base/filename.c (mu_get_full_path): Likewise.
* libmailutils/base/tempfile.c (mu_tempfile): Likewise.
* libmailutils/base/url.c (_url_path_default): Likewise.
* libmu_auth/virtual.c (getpwnam_virtual)
(mu_auth_virt_domain_by_name): Likewise.
* libmu_sieve/extensions/vacation.c (check_db): Likewise.
* libmu_sieve/sieve.l (_try_include): Likewise.
* maidag/forward.c (maidag_forward): Likewise.

* mh/mh.h (mh_safe_make_file_name): New proto.
* mh/mh_init.c (mh_audit_open,mh_get_dir)
(mh_expand_name,mh_real_install): Use mh_safe_make_file_name.
(mh_safe_make_file_name): New function.
* mh/folder.c (read_seq_file, _scan): Use mh_safe_make_file_name.
* mh/mh_global.c (mh_read_profile, _mh_init_global_sequences): Likewise.
* mh/install-mh.c (main): Likewise.
* mh/mhn.c (normalize_path, store_handler, main): Likewise.
* mh/repl.c (make_draft): Likewise.
* mh/rmf.c (rmf): Likewise.
* mh/sortm.c (swap_message): Likewise.
* mimeview/mimetypes.l (mimetypes_open): Likewise.

* lib/mailcap.c: Add error checking.
1 parent e3ef44ef
...@@ -375,9 +375,15 @@ run_user_action (FILE *tty, const char *cr, mu_message_t msg) ...@@ -375,9 +375,15 @@ run_user_action (FILE *tty, const char *cr, mu_message_t msg)
375 char *cwd = mu_getcwd (); 375 char *cwd = mu_getcwd ();
376 char *rcname; 376 char *rcname;
377 377
378 mu_asprintf (&rcname, "%s/%s", cwd, BIFF_RC); 378 rcname = mu_make_file_name (cwd, BIFF_RC);
379 free (cwd); 379 free (cwd);
380 380 if (!rcname)
381 {
382 mu_diag_funcall (MU_DIAG_ERROR, "mu_make_file_name", NULL, ENOMEM);
383 fclose (fp);
384 return;
385 }
386
381 mu_diag_get_debug (&debug); 387 mu_diag_get_debug (&debug);
382 388
383 while ((n = act_getline (fp, &stmt, &size))) 389 while ((n = act_getline (fp, &stmt, &size)))
......
...@@ -34,8 +34,8 @@ imap4d_lsub (struct imap4d_command *command, imap4d_tokbuf_t tok) ...@@ -34,8 +34,8 @@ imap4d_lsub (struct imap4d_command *command, imap4d_tokbuf_t tok)
34 { 34 {
35 char *ref; 35 char *ref;
36 char *wcard; 36 char *wcard;
37 char *file = NULL; 37 char *file;
38 char *pattern = NULL; 38 char *pattern;
39 const char *delim = "/"; 39 const char *delim = "/";
40 FILE *fp; 40 FILE *fp;
41 41
...@@ -45,11 +45,11 @@ imap4d_lsub (struct imap4d_command *command, imap4d_tokbuf_t tok) ...@@ -45,11 +45,11 @@ imap4d_lsub (struct imap4d_command *command, imap4d_tokbuf_t tok)
45 ref = imap4d_tokbuf_getarg (tok, IMAP4_ARG_1); 45 ref = imap4d_tokbuf_getarg (tok, IMAP4_ARG_1);
46 wcard = imap4d_tokbuf_getarg (tok, IMAP4_ARG_2); 46 wcard = imap4d_tokbuf_getarg (tok, IMAP4_ARG_2);
47 47
48 asprintf (&pattern, "%s%s", ref, wcard); 48 pattern = mu_make_file_name (ref, wcard);
49 if (!pattern) 49 if (!pattern)
50 return io_completion_response (command, RESP_NO, "Not enough memory"); 50 return io_completion_response (command, RESP_NO, "Not enough memory");
51 51
52 asprintf (&file, "%s/.mailboxlist", real_homedir); 52 file = mu_make_file_name (real_homedir, ".mailboxlist");
53 if (!file) 53 if (!file)
54 { 54 {
55 free (pattern); 55 free (pattern);
......
...@@ -40,7 +40,9 @@ imap4d_subscribe (struct imap4d_command *command, imap4d_tokbuf_t tok) ...@@ -40,7 +40,9 @@ imap4d_subscribe (struct imap4d_command *command, imap4d_tokbuf_t tok)
40 40
41 name = imap4d_tokbuf_getarg (tok, IMAP4_ARG_1); 41 name = imap4d_tokbuf_getarg (tok, IMAP4_ARG_1);
42 42
43 asprintf (&file, "%s/.mailboxlist", real_homedir); 43 file = mu_make_file_name (real_homedir, ".mailboxlist");
44 if (!file)
45 return io_completion_response (command, RESP_NO, "Cannot subscribe");
44 fp = fopen (file, "a"); 46 fp = fopen (file, "a");
45 free (file); 47 free (file);
46 if (fp) 48 if (fp)
......
...@@ -99,7 +99,13 @@ imap4d_unsubscribe (struct imap4d_command *command, imap4d_tokbuf_t tok) ...@@ -99,7 +99,13 @@ imap4d_unsubscribe (struct imap4d_command *command, imap4d_tokbuf_t tok)
99 99
100 name = imap4d_tokbuf_getarg (tok, IMAP4_ARG_1); 100 name = imap4d_tokbuf_getarg (tok, IMAP4_ARG_1);
101 101
102 asprintf (&file, "%s/.mailboxlist", real_homedir); 102 file = mu_make_file_name (real_homedir, ".mailboxlist");
103 if (!file)
104 {
105 mu_diag_funcall (MU_DIAG_ERROR, "mu_make_file_name", NULL, ENOMEM);
106 return io_completion_response (command, RESP_NO, "Cannot unsubscribe");
107 }
108
103 sd.result = 0; 109 sd.result = 0;
104 sd.name = name; 110 sd.name = name;
105 111
......
...@@ -660,10 +660,12 @@ display_stream_mailcap (const char *ident, mu_stream_t stream, mu_header_t hdr, ...@@ -660,10 +660,12 @@ display_stream_mailcap (const char *ident, mu_stream_t stream, mu_header_t hdr,
660 char *home = mu_get_homedir (); 660 char *home = mu_get_homedir ();
661 asprintf (&mailcap_path, "%s/.mailcap:%s", home, DEFAULT_MAILCAP); 661 asprintf (&mailcap_path, "%s/.mailcap:%s", home, DEFAULT_MAILCAP);
662 free (home); 662 free (home);
663 if (!mailcap_path)
664 return 1;
663 } 665 }
664 else 666 else
665 mailcap_path = strdup (mailcap_path); 667 mailcap_path = strdup (mailcap_path);
666 668
667 obstack_init (&expand_stack); 669 obstack_init (&expand_stack);
668 670
669 for (p = strtok_r (mailcap_path, ":", &sp); p; p = strtok_r (NULL, ":", &sp)) 671 for (p = strtok_r (mailcap_path, ":", &sp); p; p = strtok_r (NULL, ":", &sp))
......
...@@ -59,14 +59,11 @@ mu_get_full_path (const char *file) ...@@ -59,14 +59,11 @@ mu_get_full_path (const char *file)
59 char *cwd = mu_getcwd (); 59 char *cwd = mu_getcwd ();
60 if (cwd) 60 if (cwd)
61 { 61 {
62 p = calloc (strlen (cwd) + 1 + strlen (file) + 1, 1); 62 p = mu_make_file_name (cwd, file);
63 if (p)
64 sprintf (p, "%s/%s", cwd, file);
65 free (cwd); 63 free (cwd);
66 } 64 }
67 } 65 }
68 66 else
69 if (!p)
70 p = strdup (file); 67 p = strdup (file);
71 return p; 68 return p;
72 } 69 }
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
31 #include <mailutils/io.h> 31 #include <mailutils/io.h>
32 #include <mailutils/error.h> 32 #include <mailutils/error.h>
33 #include <mailutils/errno.h> 33 #include <mailutils/errno.h>
34 #include <mailutils/util.h>
34 35
35 /* Create and open a temporary file. Be very careful about it, since we 36 /* Create and open a temporary file. Be very careful about it, since we
36 may be running with extra privilege i.e setgid(). 37 may be running with extra privilege i.e setgid().
...@@ -52,8 +53,12 @@ mu_tempfile (const char *tmpdir, char **namep) ...@@ -52,8 +53,12 @@ mu_tempfile (const char *tmpdir, char **namep)
52 if (!tmpdir) 53 if (!tmpdir)
53 tmpdir = (getenv ("TMPDIR")) ? getenv ("TMPDIR") : P_tmpdir; 54 tmpdir = (getenv ("TMPDIR")) ? getenv ("TMPDIR") : P_tmpdir;
54 55
55 if (mu_asprintf (&filename, "%s/muXXXXXX", tmpdir)) 56 filename = mu_make_file_name (tmpdir, "muXXXXXX");
56 return -1; 57 if (!filename)
58 {
59 mu_diag_funcall (MU_DIAG_ERROR, "mu_make_file_name", NULL, ENOMEM);
60 return -1;
61 }
57 62
58 #ifdef HAVE_MKSTEMP 63 #ifdef HAVE_MKSTEMP
59 { 64 {
......
...@@ -956,12 +956,7 @@ mu_url_init (mu_url_t url, int port, const char *scheme) ...@@ -956,12 +956,7 @@ mu_url_init (mu_url_t url, int port, const char *scheme)
956 static char * 956 static char *
957 _url_path_default (const char *spooldir, const char *user, int unused) 957 _url_path_default (const char *spooldir, const char *user, int unused)
958 { 958 {
959 char *mbox = malloc (strlen (spooldir) + strlen (user) + 2); 959 return mu_make_file_name (spooldir, user);
960 if (!mbox)
961 errno = ENOMEM;
962 else
963 sprintf (mbox, "%s/%s", spooldir, user);
964 return mbox;
965 } 960 }
966 961
967 /* Hashed indexing */ 962 /* Hashed indexing */
......
...@@ -52,6 +52,7 @@ ...@@ -52,6 +52,7 @@
52 #include <mailutils/mu_auth.h> 52 #include <mailutils/mu_auth.h>
53 #include <mailutils/nls.h> 53 #include <mailutils/nls.h>
54 #include <mailutils/errno.h> 54 #include <mailutils/errno.h>
55 #include <mailutils/util.h>
55 56
56 #ifdef ENABLE_VIRTUAL_DOMAINS 57 #ifdef ENABLE_VIRTUAL_DOMAINS
57 58
...@@ -89,12 +90,10 @@ getpwnam_virtual (const char *u) ...@@ -89,12 +90,10 @@ getpwnam_virtual (const char *u)
89 if (delim == 0) 90 if (delim == 0)
90 return NULL; 91 return NULL;
91 92
92 filename = malloc (strlen (mu_virtual_module_config.pwddir) + 93 filename = mu_make_file_name (mu_virtual_module_config.pwddir, &u[delim + 1]);
93 strlen (&u[delim + 1]) + 2 /* slash and null byte */);
94 if (filename == NULL) 94 if (filename == NULL)
95 return NULL; 95 return NULL;
96 96
97 sprintf (filename, "%s/%s", mu_virtual_module_config.pwddir, &u[delim + 1]);
98 pfile = fopen (filename, "r"); 97 pfile = fopen (filename, "r");
99 free (filename); 98 free (filename);
100 99
...@@ -173,10 +172,9 @@ mu_auth_virt_domain_by_name (struct mu_auth_data **return_data, ...@@ -173,10 +172,9 @@ mu_auth_virt_domain_by_name (struct mu_auth_data **return_data,
173 return MU_ERR_AUTH_FAILURE; 172 return MU_ERR_AUTH_FAILURE;
174 } 173 }
175 174
176 mailbox_name = calloc (strlen (pw->pw_dir) + strlen ("/INBOX") + 1, 1); 175 mailbox_name = mu_make_file_name (pw->pw_dir, "INBOX");
177 if (!mailbox_name) 176 if (!mailbox_name)
178 return ENOMEM; 177 return ENOMEM;
179 sprintf (mailbox_name, "%s/INBOX", pw->pw_dir);
180 178
181 rc = mu_auth_data_alloc (return_data, 179 rc = mu_auth_data_alloc (return_data,
182 pw->pw_name, 180 pw->pw_name,
......
...@@ -300,7 +300,8 @@ check_db (mu_sieve_machine_t mach, mu_list_t tags, char *from) ...@@ -300,7 +300,8 @@ check_db (mu_sieve_machine_t mach, mu_list_t tags, char *from)
300 300
301 home = mu_get_homedir (); 301 home = mu_get_homedir ();
302 302
303 if (asprintf (&file, "%s/.vacation", (home ? home : ".")) == -1) 303 file = mu_make_file_name (home ? home : ".", ".vacation");
304 if (!file)
304 { 305 {
305 mu_sieve_error (mach, _("%lu: cannot build db file name"), 306 mu_sieve_error (mach, _("%lu: cannot build db file name"),
306 (unsigned long) mu_sieve_get_message_num (mach)); 307 (unsigned long) mu_sieve_get_message_num (mach));
......
...@@ -349,11 +349,13 @@ static int ...@@ -349,11 +349,13 @@ static int
349 _try_include (void *item, void *data) 349 _try_include (void *item, void *data)
350 { 350 {
351 char **dir = data; 351 char **dir = data;
352 char *name = malloc (strlen (item) + 1 + strlen (*dir) + 1); 352 char *name = mu_make_file_name ((char*) item, *dir);
353 353
354 if (!name) 354 if (!name)
355 return 0; 355 {
356 sprintf (name, "%s/%s", (char*) item, *dir); 356 mu_diag_funcall (MU_DIAG_ERROR, "mu_make_file_name", NULL, ENOMEM);
357 return 0;
358 }
357 if (access (name, R_OK) == 0) 359 if (access (name, R_OK) == 0)
358 { 360 {
359 *(char**) data = name; 361 *(char**) data = name;
......
...@@ -342,7 +342,7 @@ maidag_forward (mu_message_t msg, struct mu_auth_data *auth, char *fwfile) ...@@ -342,7 +342,7 @@ maidag_forward (mu_message_t msg, struct mu_auth_data *auth, char *fwfile)
342 auth->dir, mu_strerror (errno)); 342 auth->dir, mu_strerror (errno));
343 return maidag_forward_none; 343 return maidag_forward_none;
344 } 344 }
345 asprintf (&filename, "%s/%s", auth->dir, fwfile); 345 filename = mu_make_file_name (auth->dir, fwfile);
346 } 346 }
347 else 347 else
348 filename = strdup (fwfile); 348 filename = strdup (fwfile);
......
...@@ -275,9 +275,7 @@ read_seq_file (struct folder_info *info, const char *prefix, const char *name) ...@@ -275,9 +275,7 @@ read_seq_file (struct folder_info *info, const char *prefix, const char *name)
275 mh_context_t *ctx; 275 mh_context_t *ctx;
276 const char *p; 276 const char *p;
277 277
278 asprintf (&pname, "%s/%s", prefix, name); 278 pname = mh_safe_make_file_name (prefix, name);
279 if (!pname)
280 abort ();
281 ctx = mh_context_create (pname, 1); 279 ctx = mh_context_create (pname, 1);
282 mh_context_read (ctx); 280 mh_context_read (ctx);
283 281
...@@ -350,7 +348,7 @@ _scan (const char *name, size_t depth) ...@@ -350,7 +348,7 @@ _scan (const char *name, size_t depth)
350 } 348 }
351 else if (entry->d_name[0] != ',') 349 else if (entry->d_name[0] != ',')
352 { 350 {
353 asprintf (&p, "%s/%s", name, entry->d_name); 351 p = mh_safe_make_file_name (name, entry->d_name);
354 if (stat (p, &st) < 0) 352 if (stat (p, &st) < 0)
355 mu_diag_funcall (MU_DIAG_ERROR, "stat", p, errno); 353 mu_diag_funcall (MU_DIAG_ERROR, "stat", p, errno);
356 else if (S_ISDIR (st.st_mode)) 354 else if (S_ISDIR (st.st_mode))
...@@ -378,7 +376,7 @@ _scan (const char *name, size_t depth) ...@@ -378,7 +376,7 @@ _scan (const char *name, size_t depth)
378 376
379 if (info.cur) 377 if (info.cur)
380 { 378 {
381 asprintf (&p, "%s/%s", name, mu_umaxtostr (0, info.cur)); 379 p = mh_safe_make_file_name (name, mu_umaxtostr (0, info.cur));
382 if (stat (p, &st) < 0 || !S_ISREG (st.st_mode)) 380 if (stat (p, &st) < 0 || !S_ISREG (st.st_mode))
383 info.cur = 0; 381 info.cur = 0;
384 free (p); 382 free (p);
......
...@@ -71,8 +71,7 @@ main (int argc, char **argv) ...@@ -71,8 +71,7 @@ main (int argc, char **argv)
71 home = mu_get_homedir (); 71 home = mu_get_homedir ();
72 if (!home) 72 if (!home)
73 abort (); /* shouldn't happen */ 73 abort (); /* shouldn't happen */
74 asprintf (&name, "%s/%s", home, MH_USER_PROFILE); 74 name = mh_safe_make_file_name (home, MH_USER_PROFILE);
75
76 mh_install (name, automode); 75 mh_install (name, automode);
77 return 0; 76 return 0;
78 } 77 }
......
...@@ -368,3 +368,5 @@ int check_draft_disposition (struct mh_whatnow_env *wh, int use_draft); ...@@ -368,3 +368,5 @@ int check_draft_disposition (struct mh_whatnow_env *wh, int use_draft);
368 void ali_parse_error (const char *fmt, ...) MU_PRINTFLIKE(1,2); 368 void ali_parse_error (const char *fmt, ...) MU_PRINTFLIKE(1,2);
369 void ali_verbatim (int enable); 369 void ali_verbatim (int enable);
370 370
371 char *mh_safe_make_file_name (const char *dir, const char *file);
372
......
...@@ -61,7 +61,7 @@ mh_read_profile () ...@@ -61,7 +61,7 @@ mh_read_profile ()
61 char *home = mu_get_homedir (); 61 char *home = mu_get_homedir ();
62 if (!home) 62 if (!home)
63 abort (); /* shouldn't happen */ 63 abort (); /* shouldn't happen */
64 asprintf (&p, "%s/%s", home, MH_USER_PROFILE); 64 p = mh_safe_make_file_name (home, MH_USER_PROFILE);
65 free (home); 65 free (home);
66 } 66 }
67 67
...@@ -152,7 +152,7 @@ _mh_init_global_sequences () ...@@ -152,7 +152,7 @@ _mh_init_global_sequences ()
152 _mh_init_global_context (); 152 _mh_init_global_context ();
153 name = mh_global_profile_get ("mh-sequences", MH_SEQUENCES_FILE); 153 name = mh_global_profile_get ("mh-sequences", MH_SEQUENCES_FILE);
154 p = mh_expand_name (NULL, current_folder, 0); 154 p = mh_expand_name (NULL, current_folder, 0);
155 asprintf (&seq_name, "%s/%s", p, name); 155 seq_name = mh_safe_make_file_name (p, name);
156 free (p); 156 free (p);
157 sequences = mh_context_create (seq_name, 1); 157 sequences = mh_context_create (seq_name, 1);
158 if (mh_context_read (sequences) == 0) 158 if (mh_context_read (sequences) == 0)
......
...@@ -381,14 +381,7 @@ mh_audit_open (char *name, mu_mailbox_t mbox) ...@@ -381,14 +381,7 @@ mh_audit_open (char *name, mu_mailbox_t mbox)
381 namep = mu_tilde_expansion (name, "/", NULL); 381 namep = mu_tilde_expansion (name, "/", NULL);
382 if (strchr (namep, '/') == NULL) 382 if (strchr (namep, '/') == NULL)
383 { 383 {
384 char *p = NULL; 384 char *p = mh_safe_make_file_name (mu_folder_directory (), namep);
385
386 asprintf (&p, "%s/%s", mu_folder_directory (), namep);
387 if (!p)
388 {
389 mu_error (_("not enough memory"));
390 exit (1);
391 }
392 free (namep); 385 free (namep);
393 namep = p; 386 namep = p;
394 } 387 }
...@@ -467,11 +460,16 @@ mh_get_dir () ...@@ -467,11 +460,16 @@ mh_get_dir ()
467 if (mhdir[0] != '/') 460 if (mhdir[0] != '/')
468 { 461 {
469 char *p = mu_get_homedir (); 462 char *p = mu_get_homedir ();
470 asprintf (&mhcopy, "%s/%s", p, mhdir); 463 mhcopy = mh_safe_make_file_name (p, mhdir);
471 free (p); 464 free (p);
472 } 465 }
473 else 466 else
474 mhcopy = strdup (mhdir); 467 mhcopy = strdup (mhdir);
468 if (!mhcopy)
469 {
470 mu_error (_("not enough memory"));
471 abort ();
472 }
475 return mhcopy; 473 return mhcopy;
476 } 474 }
477 475
...@@ -487,8 +485,7 @@ mh_expand_name (const char *base, const char *name, int is_folder) ...@@ -487,8 +485,7 @@ mh_expand_name (const char *base, const char *name, int is_folder)
487 else if (strncmp (namep, "../", 3) == 0 || strncmp (namep, "./", 2) == 0) 485 else if (strncmp (namep, "../", 3) == 0 || strncmp (namep, "./", 2) == 0)
488 { 486 {
489 char *cwd = mu_getcwd (); 487 char *cwd = mu_getcwd ();
490 char *tmp = NULL; 488 char *tmp = mh_safe_make_file_name (cwd, namep);
491 asprintf (&tmp, "%s/%s", cwd, namep);
492 free (cwd); 489 free (cwd);
493 free (namep); 490 free (namep);
494 namep = tmp; 491 namep = tmp;
...@@ -698,7 +695,7 @@ mh_real_install (char *name, int automode) ...@@ -698,7 +695,7 @@ mh_real_install (char *name, int automode)
698 char *ctx; 695 char *ctx;
699 FILE *fp; 696 FILE *fp;
700 697
701 asprintf (&mhdir, "%s/%s", home, "Mail"); 698 mhdir = mh_safe_make_file_name (home, "Mail");
702 699
703 if (!automode) 700 if (!automode)
704 { 701 {
...@@ -736,7 +733,7 @@ mh_real_install (char *name, int automode) ...@@ -736,7 +733,7 @@ mh_real_install (char *name, int automode)
736 free (mhdir); 733 free (mhdir);
737 if (local) 734 if (local)
738 { 735 {
739 asprintf (&mhdir, "%s/%s", home, p); 736 mhdir = mh_safe_make_file_name (home, p);
740 free (p); 737 free (p);
741 } 738 }
742 else 739 else
...@@ -756,7 +753,7 @@ mh_real_install (char *name, int automode) ...@@ -756,7 +753,7 @@ mh_real_install (char *name, int automode)
756 fprintf (fp, "Path: %s\n", mhdir); 753 fprintf (fp, "Path: %s\n", mhdir);
757 fclose (fp); 754 fclose (fp);
758 755
759 asprintf (&ctx, "%s/%s", mhdir, MH_CONTEXT_FILE); 756 ctx = mh_safe_make_file_name (mhdir, MH_CONTEXT_FILE);
760 fp = fopen (ctx, "w"); 757 fp = fopen (ctx, "w");
761 if (fp) 758 if (fp)
762 { 759 {
...@@ -764,7 +761,7 @@ mh_real_install (char *name, int automode) ...@@ -764,7 +761,7 @@ mh_real_install (char *name, int automode)
764 fclose (fp); 761 fclose (fp);
765 } 762 }
766 free (ctx); 763 free (ctx);
767 asprintf (&ctx, "%s/inbox", mhdir); 764 ctx = mh_safe_make_file_name (mhdir, "inbox");
768 if (mh_check_folder (ctx, !automode)) 765 if (mh_check_folder (ctx, !automode))
769 exit (1); 766 exit (1);
770 free (ctx); 767 free (ctx);
...@@ -1029,3 +1026,17 @@ mh_draft_message (const char *name, const char *msgspec, char **pname) ...@@ -1029,3 +1026,17 @@ mh_draft_message (const char *name, const char *msgspec, char **pname)
1029 mu_mailbox_destroy (&mbox); 1026 mu_mailbox_destroy (&mbox);
1030 return rc; 1027 return rc;
1031 } 1028 }
1029
1030 char *
1031 mh_safe_make_file_name (const char *dir, const char *file)
1032 {
1033 file = mu_make_file_name (dir, file);
1034 if (!file)
1035 {
1036 mu_diag_funcall (MU_DIAG_ERROR, "mu_make_file_name", NULL, ENOMEM);
1037 abort ();
1038 }
1039 return file;
1040 }
1041
1042
......
...@@ -1487,10 +1487,7 @@ normalize_path (const char *cwd, char *path) ...@@ -1487,10 +1487,7 @@ normalize_path (const char *cwd, char *path)
1487 if (!cwd) 1487 if (!cwd)
1488 cwd = pcwd = mu_getcwd (); 1488 cwd = pcwd = mu_getcwd ();
1489 1489
1490 len = strlen (cwd) + strlen (path) + 2; 1490 path = mh_safe_make_file_name (cwd, path);
1491 p = xmalloc (len);
1492 sprintf (p, "%s/%s", cwd, path);
1493 path = p;
1494 1491
1495 /* delete trailing delimiter if any */ 1492 /* delete trailing delimiter if any */
1496 if (len && path[len-1] == '/') 1493 if (len && path[len-1] == '/')
...@@ -1576,7 +1573,7 @@ store_handler (mu_message_t msg, msg_part_t part, char *type, char *encoding, ...@@ -1576,7 +1573,7 @@ store_handler (mu_message_t msg, msg_part_t part, char *type, char *encoding,
1576 { 1573 {
1577 char *fname = mhn_store_command (msg, part, prefix); 1574 char *fname = mhn_store_command (msg, part, prefix);
1578 if (dir) 1575 if (dir)
1579 asprintf (&name, "%s/%s", dir, fname); 1576 name = mh_safe_make_file_name (dir, fname);
1580 else 1577 else
1581 name = fname; 1578 name = fname;
1582 } 1579 }
...@@ -2670,7 +2667,7 @@ main (int argc, char **argv) ...@@ -2670,7 +2667,7 @@ main (int argc, char **argv)
2670 case mode_compose: 2667 case mode_compose:
2671 /* Prepare filename for diagnostic purposes */ 2668 /* Prepare filename for diagnostic purposes */
2672 if (input_file[0] != '/') 2669 if (input_file[0] != '/')
2673 asprintf (&input_file, "%s/%s", mu_folder_directory (), input_file); 2670 input_file = mh_safe_make_file_name (mu_folder_directory (), input_file);
2674 rc = mhn_compose (); 2671 rc = mhn_compose ();
2675 break; 2672 break;
2676 2673
......
...@@ -372,8 +372,8 @@ make_draft (mu_mailbox_t mbox, int disp, struct mh_whatnow_env *wh) ...@@ -372,8 +372,8 @@ make_draft (mu_mailbox_t mbox, int disp, struct mh_whatnow_env *wh)
372 372
373 mu_mailbox_get_url (mbox, &url); 373 mu_mailbox_get_url (mbox, &url);
374 mh_message_number (msg, &num); 374 mh_message_number (msg, &num);
375 asprintf (&msgname, "%s/%s", 375 msgname = mh_safe_make_file_name (mu_url_to_string (url),
376 mu_url_to_string (url), mu_umaxtostr (0, num)); 376 mu_umaxtostr (0, num));
377 p = strchr (msgname, ':'); 377 p = strchr (msgname, ':');
378 if (!p) 378 if (!p)
379 wh->msg = msgname; 379 wh->msg = msgname;
......
...@@ -131,7 +131,7 @@ rmf (const char *name) ...@@ -131,7 +131,7 @@ rmf (const char *name)
131 || strcmp (entry->d_name, "..") == 0) 131 || strcmp (entry->d_name, "..") == 0)
132 continue; 132 continue;
133 133
134 asprintf (&p, "%s/%s", name, entry->d_name); 134 p = mh_safe_make_file_name (name, entry->d_name);
135 if (stat (p, &st) < 0) 135 if (stat (p, &st) < 0)
136 { 136 {
137 mu_diag_funcall (MU_DIAG_ERROR, "stat", p, errno); 137 mu_diag_funcall (MU_DIAG_ERROR, "stat", p, errno);
......
...@@ -447,8 +447,8 @@ swap_message (size_t a, size_t b) ...@@ -447,8 +447,8 @@ swap_message (size_t a, size_t b)
447 char *path_a, *path_b; 447 char *path_a, *path_b;
448 char *tmp; 448 char *tmp;
449 449
450 asprintf (&path_a, "%s/%s", mbox_path, mu_umaxtostr (0, a)); 450 path_a = mh_safe_make_file_name (mbox_path, mu_umaxtostr (0, a));
451 asprintf (&path_b, "%s/%s", mbox_path, mu_umaxtostr (1, b)); 451 path_b = mh_safe_make_file_name (mbox_path, mu_umaxtostr (1, b));
452 tmp = mu_tempname (mbox_path); 452 tmp = mu_tempname (mbox_path);
453 rename (path_a, tmp); 453 rename (path_a, tmp);
454 unlink (path_a); 454 unlink (path_a);
......
...@@ -153,7 +153,7 @@ mimetypes_open (const char *name) ...@@ -153,7 +153,7 @@ mimetypes_open (const char *name)
153 153
154 if (S_ISDIR (st.st_mode)) 154 if (S_ISDIR (st.st_mode))
155 { 155 {
156 asprintf (&file_name, "%s/mime.types", name); 156 file_name = mu_make_file_name (name, "mime.types");
157 file_name_alloc = 1; 157 file_name_alloc = 1;
158 } 158 }
159 else 159 else
......