Commit cef55358 authored by Rocco Rutte's avatar Rocco Rutte

Use realpath() in mutt_pretty_mailbox() for paths that may need it.

This requires to add the buffer size as parameter since the result may
be longer than the original but still fit in the buffer. Closes #2948.
parent 80643307
2008-07-02 10:06 +0200 Rocco Rutte <pdmef@gmx.net> (cc2334fdf126)
* hash.c: Use casts to avoid triggering integer overflow detection in
hash function
2008-07-01 20:06 -0700 Vincent Lefevre <vincent@vinc17.org> (fb0df4ae0836)
* ChangeLog, curs_lib.c: Clamp timeval math to unsigned int to match
progress timestamps. This is fine since only relative differences
matter. Closes #3018.
2008-07-01 18:29 -0700 Brendan Cully <brendan@kublai.com> (f9af0501d2dd)
* crypt-gpgme.c: Set GPGME locale on first attempt to create context.
......
......@@ -462,7 +462,7 @@ static int examine_mailboxes (MUTTMENU *menu, struct browser_state *state)
continue;
strfcpy (buffer, NONULL(tmp->path), sizeof (buffer));
mutt_pretty_mailbox (buffer);
mutt_pretty_mailbox (buffer, sizeof (buffer));
add_folder (menu, state, buffer, &s, tmp->new);
}
......@@ -508,7 +508,7 @@ static void init_menu (struct browser_state *state, MUTTMENU *menu, char *title,
else
{
strfcpy (path, LastDir, sizeof (path));
mutt_pretty_mailbox (path);
mutt_pretty_mailbox (path, sizeof (path));
#ifdef USE_IMAP
if (state->imap_browse && option (OPTIMAPLSUB))
snprintf (title, titlelen, _("Subscribed [%s], File mask: %s"),
......
......@@ -429,7 +429,7 @@ int mutt_buffy_list (void)
continue;
strfcpy (path, tmp->path, sizeof (path));
mutt_pretty_mailbox (path);
mutt_pretty_mailbox (path, sizeof (path));
if (!first && pos + strlen (path) >= COLS - 7)
break;
......@@ -502,7 +502,7 @@ void mutt_buffy (char *s, size_t slen)
break;
}
strfcpy (s, tmp->path, slen);
mutt_pretty_mailbox (s);
mutt_pretty_mailbox (s, slen);
break;
default:
......@@ -528,7 +528,7 @@ void mutt_buffy (char *s, size_t slen)
break;
}
strfcpy (s, tmp->path, slen);
mutt_pretty_mailbox (s);
mutt_pretty_mailbox (s, slen);
break;
}
}
......@@ -758,7 +758,7 @@ int mutt_save_message (HEADER *h, int delete,
}
}
mutt_pretty_mailbox (buf);
mutt_pretty_mailbox (buf, sizeof (buf));
if (mutt_enter_fname (prompt, buf, sizeof (buf), redraw, 0) == -1)
return (-1);
......
......@@ -217,7 +217,7 @@ check_attachments(ATTACHPTR **idx, short idxlen)
strfcpy(pretty, idx[i]->content->filename, sizeof(pretty));
if(stat(idx[i]->content->filename, &st) != 0)
{
mutt_pretty_mailbox(pretty);
mutt_pretty_mailbox(pretty, sizeof (pretty));
mutt_error(_("%s [#%d] no longer exists!"),
pretty, i+1);
return -1;
......@@ -225,7 +225,7 @@ check_attachments(ATTACHPTR **idx, short idxlen)
if(idx[i]->content->stamp < st.st_mtime)
{
mutt_pretty_mailbox(pretty);
mutt_pretty_mailbox(pretty, sizeof (pretty));
snprintf(msg, sizeof(msg), _("%s [#%d] modified. Update encoding?"),
pretty, i+1);
......@@ -568,8 +568,8 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */
strfcpy (buf, fcc, sizeof (buf));
if (mutt_get_field ("Fcc: ", buf, sizeof (buf), M_FILE | M_CLEAR) == 0)
{
strfcpy (fcc, buf, _POSIX_PATH_MAX);
mutt_pretty_mailbox (fcc);
strfcpy (fcc, buf, fcclen);
mutt_pretty_mailbox (fcc, fcclen);
move (HDR_FCC, HDR_XOFFSET);
mutt_paddstr (W, fcc);
fccSet = 1;
......@@ -717,7 +717,7 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */
if (Context)
{
strfcpy (fname, NONULL (Context->path), sizeof (fname));
mutt_pretty_mailbox (fname);
mutt_pretty_mailbox (fname, sizeof (fname));
}
if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1) == -1 || !fname[0])
......@@ -1005,7 +1005,7 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */
case OP_COMPOSE_RENAME_FILE:
CHECK_COUNT;
strfcpy (fname, idx[menu->current]->content->filename, sizeof (fname));
mutt_pretty_mailbox (fname);
mutt_pretty_mailbox (fname, sizeof (fname));
if (mutt_get_field (_("Rename to: "), fname, sizeof (fname), M_FILE)
== 0 && fname[0])
{
......@@ -1194,7 +1194,7 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */
if (Context)
{
strfcpy (fname, NONULL (Context->path), sizeof (fname));
mutt_pretty_mailbox (fname);
mutt_pretty_mailbox (fname, sizeof (fname));
}
if (idxlen)
msg->content = idx[0]->content;
......
......@@ -1071,7 +1071,7 @@ int mutt_index_menu (void)
if ((op == OP_MAIN_NEXT_UNREAD_MAILBOX) && Context && Context->path)
{
strfcpy (buf, Context->path, sizeof (buf));
mutt_pretty_mailbox (buf);
mutt_pretty_mailbox (buf, sizeof (buf));
mutt_buffy (buf, sizeof (buf));
if (!buf[0])
{
......
......@@ -572,7 +572,7 @@ int _mutt_enter_string (char *buf, size_t buflen, int y, int x,
set_option (OPTNEEDREDRAW);
if (*buf)
{
mutt_pretty_mailbox (buf);
mutt_pretty_mailbox (buf, buflen);
if (!pass)
mutt_history_add (hclass, buf, 1);
rv = 0;
......
......@@ -143,7 +143,7 @@ void mutt_edit_headers (const char *editor,
if (*p)
{
strfcpy (fcc, p, fcclen);
mutt_pretty_mailbox (fcc);
mutt_pretty_mailbox (fcc, fcclen);
}
keep = 0;
}
......@@ -173,7 +173,7 @@ void mutt_edit_headers (const char *editor,
}
else
{
mutt_pretty_mailbox (path);
mutt_pretty_mailbox (path, sizeof (path));
mutt_error (_("%s: unable to attach file"), path);
}
}
......
......@@ -426,7 +426,7 @@ void mutt_select_fcc (char *path, size_t pathlen, HEADER *hdr)
else
strfcpy (path, NONULL (Outbox), pathlen);
}
mutt_pretty_mailbox (path);
mutt_pretty_mailbox (path, pathlen);
}
static char *_mutt_string_hook (const char *match, int hook)
......
......@@ -1990,7 +1990,7 @@ int imap_complete(char* dest, size_t dlen, char* path) {
{
/* reformat output */
imap_qualify_path (dest, dlen, &mx, completion);
mutt_pretty_mailbox (dest);
mutt_pretty_mailbox (dest, dlen);
FREE (&mx.mbox);
return 0;
......
......@@ -1856,7 +1856,7 @@ static int parse_set (BUFFER *tmp, BUFFER *s, unsigned long data, BUFFER *err)
{
_tmp[0] = '\0';
strfcpy (_tmp, NONULL(*((char **) MuttVars[idx].data)), sizeof (_tmp));
mutt_pretty_mailbox (_tmp);
mutt_pretty_mailbox (_tmp, sizeof (_tmp));
val = _tmp;
}
else
......@@ -2618,7 +2618,7 @@ static int var_to_string (int idx, char* val, size_t len)
{
strfcpy (tmp, NONULL (*((char **) MuttVars[idx].data)), sizeof (tmp));
if (DTYPE (MuttVars[idx].type) == DT_PATH)
mutt_pretty_mailbox (tmp);
mutt_pretty_mailbox (tmp, sizeof (tmp));
}
else if (DTYPE (MuttVars[idx].type) == DT_ADDR)
{
......
......@@ -956,7 +956,7 @@ int mbox_sync_mailbox (CONTEXT *ctx, int *index_hint)
rename (tempfile, savefile);
mutt_unblock_signals ();
mx_fastclose_mailbox (ctx);
mutt_pretty_mailbox (savefile);
mutt_pretty_mailbox (savefile, sizeof (savefile));
mutt_error (_("Write failed! Saved partial mailbox to %s"), savefile);
mutt_sleep (5);
return (-1);
......
......@@ -753,11 +753,12 @@ void mutt_free_alias (ALIAS **p)
}
/* collapse the pathname using ~ or = when possible */
void mutt_pretty_mailbox (char *s)
void mutt_pretty_mailbox (char *s, size_t buflen)
{
char *p = s, *q = s;
size_t len;
url_scheme_t scheme;
char tmp[_POSIX_PATH_MAX];
scheme = url_check_scheme (s);
......@@ -779,24 +780,34 @@ void mutt_pretty_mailbox (char *s)
q = strchr (p, '\0');
p = q;
}
/* first attempt to collapse the pathname */
while (*p)
/* cleanup path */
if (strstr (p, "//") || strstr (p, "/./"))
{
if (*p == '/' && p[1] == '/')
{
*q++ = '/';
p += 2;
}
else if (p[0] == '/' && p[1] == '.' && p[2] == '/')
/* first attempt to collapse the pathname, this is more
* lightweight than realpath() and doesn't resolve links
*/
while (*p)
{
*q++ = '/';
p += 3;
if (*p == '/' && p[1] == '/')
{
*q++ = '/';
p += 2;
}
else if (p[0] == '/' && p[1] == '.' && p[2] == '/')
{
*q++ = '/';
p += 3;
}
else
*q++ = *p++;
}
else
*q++ = *p++;
*q = 0;
}
*q = 0;
else if (strstr (p, "..") &&
(scheme == U_UNKNOWN || scheme == U_FILE) &&
realpath (p, tmp))
strfcpy (p, tmp, buflen - (p - s));
if (mutt_strncmp (s, Maildir, (len = mutt_strlen (Maildir))) == 0 &&
s[len] == '/')
......
......@@ -322,7 +322,7 @@ int mutt_get_postponed (CONTEXT *ctx, HEADER *hdr, HEADER **cur, char *fcc, size
p = tmp->data + 11;
SKIPWS (p);
strfcpy (fcc, p, fcclen);
mutt_pretty_mailbox (fcc);
mutt_pretty_mailbox (fcc, fcclen);
/* remove the X-Mutt-Fcc: header field */
next = tmp->next;
......
......@@ -230,7 +230,7 @@ void mutt_parse_part (FILE *, BODY *);
void mutt_perror (const char *);
void mutt_prepare_envelope (ENVELOPE *, int);
void mutt_unprepare_envelope (ENVELOPE *);
void mutt_pretty_mailbox (char *);
void mutt_pretty_mailbox (char *, size_t);
void mutt_pretty_size (char *, size_t, LOFF_T);
void mutt_pipe_message (HEADER *);
void mutt_print_message (HEADER *);
......
......@@ -254,7 +254,7 @@ const char *mutt_attach_fmt (char *dest,
char path[_POSIX_PATH_MAX];
strfcpy (path, aptr->content->filename, sizeof (path));
mutt_pretty_mailbox (path);
mutt_pretty_mailbox (path, sizeof (path));
mutt_format_s (dest, destlen, prefix, path);
}
else
......
......@@ -1505,7 +1505,7 @@ ci_send_message (int flags, /* send mode */
main_loop:
fcc_error = 0; /* reset value since we may have failed before */
mutt_pretty_mailbox (fcc);
mutt_pretty_mailbox (fcc, sizeof (fcc));
i = mutt_compose_menu (msg, fcc, sizeof (fcc), cur);
if (i == -1)
{
......
......@@ -99,7 +99,7 @@ status_format_str (char *buf, size_t buflen, size_t col, char op, const char *sr
if (Context && Context->path)
{
strfcpy (tmp, Context->path, sizeof (tmp));
mutt_pretty_mailbox (tmp);
mutt_pretty_mailbox (tmp, sizeof (tmp));
}
else
strfcpy (tmp, _("(no mailbox)"), sizeof (tmp));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment