From 3563b25eaa9d9955c0f70bd37f91e43e56cbeb51 Mon Sep 17 00:00:00 2001 From: Rocco Rutte Date: Wed, 2 Jul 2008 11:19:14 +0200 Subject: [PATCH] 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. --- ChangeLog | 11 +++++++++++ browser.c | 4 ++-- buffy.c | 6 +++--- commands.c | 2 +- compose.c | 14 +++++++------- curs_main.c | 2 +- enter.c | 2 +- headers.c | 4 ++-- hook.c | 2 +- imap/imap.c | 2 +- init.c | 4 ++-- mbox.c | 2 +- muttlib.c | 41 ++++++++++++++++++++++++++--------------- postpone.c | 2 +- protos.h | 2 +- recvattach.c | 2 +- send.c | 2 +- status.c | 2 +- 18 files changed, 64 insertions(+), 42 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5eae52516..c299c0744 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2008-07-02 10:06 +0200 Rocco Rutte (cc2334fdf126) + + * hash.c: Use casts to avoid triggering integer overflow detection in + hash function + +2008-07-01 20:06 -0700 Vincent Lefevre (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 (f9af0501d2dd) * crypt-gpgme.c: Set GPGME locale on first attempt to create context. diff --git a/browser.c b/browser.c index 0d0122169..4d76f7db4 100644 --- a/browser.c +++ b/browser.c @@ -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"), diff --git a/buffy.c b/buffy.c index 41e691509..8a3f6fce1 100644 --- a/buffy.c +++ b/buffy.c @@ -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; } } diff --git a/commands.c b/commands.c index 69d561bbd..19d9427e3 100644 --- a/commands.c +++ b/commands.c @@ -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); diff --git a/compose.c b/compose.c index 0957bba81..8de9fec95 100644 --- a/compose.c +++ b/compose.c @@ -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; diff --git a/curs_main.c b/curs_main.c index e39c8d017..3bb60ed08 100644 --- a/curs_main.c +++ b/curs_main.c @@ -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]) { diff --git a/enter.c b/enter.c index 3e4d4e668..fc064d956 100644 --- a/enter.c +++ b/enter.c @@ -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; diff --git a/headers.c b/headers.c index cace3a9cf..6ac21d8a1 100644 --- a/headers.c +++ b/headers.c @@ -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); } } diff --git a/hook.c b/hook.c index bee3c4878..e44b88f2b 100644 --- a/hook.c +++ b/hook.c @@ -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) diff --git a/imap/imap.c b/imap/imap.c index fec202987..62bbdcf30 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -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; diff --git a/init.c b/init.c index 2e5635bd3..3e5327f2a 100644 --- a/init.c +++ b/init.c @@ -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) { diff --git a/mbox.c b/mbox.c index bd55ee9d1..ec3a02ffd 100644 --- a/mbox.c +++ b/mbox.c @@ -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); diff --git a/muttlib.c b/muttlib.c index e0820da86..510078b38 100644 --- a/muttlib.c +++ b/muttlib.c @@ -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] == '/') diff --git a/postpone.c b/postpone.c index bcb86072a..2aa7e8cfc 100644 --- a/postpone.c +++ b/postpone.c @@ -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; diff --git a/protos.h b/protos.h index 72682bb09..99a0e707a 100644 --- a/protos.h +++ b/protos.h @@ -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 *); diff --git a/recvattach.c b/recvattach.c index 1a4628819..892751c25 100644 --- a/recvattach.c +++ b/recvattach.c @@ -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 diff --git a/send.c b/send.c index cd4d3617d..2c00de080 100644 --- a/send.c +++ b/send.c @@ -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) { diff --git a/status.c b/status.c index 09f76db39..8f19128d9 100644 --- a/status.c +++ b/status.c @@ -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)); -- 2.40.0