Commit b76d0767 b76d0767ba0a95f592d40db41fad46fdd8159a17 by Sergey Poznyakoff

(split_shortcut): Properly handle "~/" filenames.

(tilde_expand): Return MU_ERR_NO_SUCH_USER if an invalid username
was specified.
1 parent 64de3a6e
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
33 #include <mailutils/mailbox.h> 33 #include <mailutils/mailbox.h>
34 #include <mailutils/mutil.h> 34 #include <mailutils/mutil.h>
35 #include <mailutils/error.h> 35 #include <mailutils/error.h>
36 #include <mailutils/errno.h>
36 37
37 const char *mu_path_maildir = MU_PATH_MAILDIR; 38 const char *mu_path_maildir = MU_PATH_MAILDIR;
38 39
...@@ -58,13 +59,18 @@ split_shortcut (const char *file, const char pfx[], char **user, char **rest) ...@@ -58,13 +59,18 @@ split_shortcut (const char *file, const char pfx[], char **user, char **rest)
58 len = p - file + 1; 59 len = p - file + 1;
59 else 60 else
60 len = strlen (file) + 1; 61 len = strlen (file) + 1;
61
62 *user = calloc (1, len);
63 if (!*user)
64 return ENOMEM;
65 62
66 memcpy (*user, file, len); 63 if (len == 1)
67 (*user)[len-1] = 0; 64 *user = NULL;
65 else
66 {
67 *user = calloc (1, len);
68 if (!*user)
69 return ENOMEM;
70
71 memcpy (*user, file, len);
72 (*user)[len-1] = 0;
73 }
68 file += len-1; 74 file += len-1;
69 if (file[0] == '/') 75 if (file[0] == '/')
70 file++; 76 file++;
...@@ -189,11 +195,10 @@ tilde_expand (const char *file, char **buf) ...@@ -189,11 +195,10 @@ tilde_expand (const char *file, char **buf)
189 if ((status = split_shortcut (file, "~", &user, &path))) 195 if ((status = split_shortcut (file, "~", &user, &path)))
190 return status; 196 return status;
191 197
192 if (!user)
193 return ENOENT;
194 if (!path) 198 if (!path)
195 { 199 {
196 free (user); 200 if (user)
201 free (user);
197 return ENOENT; 202 return ENOENT;
198 } 203 }
199 204
...@@ -202,7 +207,7 @@ tilde_expand (const char *file, char **buf) ...@@ -202,7 +207,7 @@ tilde_expand (const char *file, char **buf)
202 { 207 {
203 free (user); 208 free (user);
204 free (path); 209 free (path);
205 return ENOENT; 210 return MU_ERR_NO_SUCH_USER;
206 } 211 }
207 212
208 free (user); /* not needed anymore */ 213 free (user); /* not needed anymore */
......