(split_shortcut): Properly handle "~/" filenames.
(tilde_expand): Return MU_ERR_NO_SUCH_USER if an invalid username was specified.
Showing
1 changed file
with
8 additions
and
3 deletions
... | @@ -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 | ||
... | @@ -59,12 +60,17 @@ split_shortcut (const char *file, const char pfx[], char **user, char **rest) | ... | @@ -59,12 +60,17 @@ split_shortcut (const char *file, const char pfx[], char **user, char **rest) |
59 | else | 60 | else |
60 | len = strlen (file) + 1; | 61 | len = strlen (file) + 1; |
61 | 62 | ||
63 | if (len == 1) | ||
64 | *user = NULL; | ||
65 | else | ||
66 | { | ||
62 | *user = calloc (1, len); | 67 | *user = calloc (1, len); |
63 | if (!*user) | 68 | if (!*user) |
64 | return ENOMEM; | 69 | return ENOMEM; |
65 | 70 | ||
66 | memcpy (*user, file, len); | 71 | memcpy (*user, file, len); |
67 | (*user)[len-1] = 0; | 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,10 +195,9 @@ tilde_expand (const char *file, char **buf) | ... | @@ -189,10 +195,9 @@ 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 | { |
200 | if (user) | ||
196 | free (user); | 201 | free (user); |
197 | return ENOENT; | 202 | return ENOENT; |
198 | } | 203 | } |
... | @@ -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 */ | ... | ... |
-
Please register or sign in to post a comment