From 0809eb0b75b47fcd11a764a21300472bb421aadb Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Sun, 10 Mar 2019 20:05:12 +0800 Subject: [PATCH] Fix imap_pretty_mailbox() call to url_ciss_tostring() Pass the correct buffer size through, so the strfcpy added in the next commit doesn't write past the end of the buffer. Co-authored-by: Richard Russon --- imap/imap.c | 2 +- imap/imap.h | 2 +- imap/util.c | 12 +++++------- muttlib.c | 2 +- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/imap/imap.c b/imap/imap.c index dcf87b4b7..d67100e1d 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -2498,7 +2498,7 @@ int imap_path_pretty(char *buf, size_t buflen, const char *folder) if (!buf || !folder) return -1; - imap_pretty_mailbox(buf, folder); + imap_pretty_mailbox(buf, buflen, folder); return 0; } diff --git a/imap/imap.h b/imap/imap.h index b2bf2a2b9..fa55eb700 100644 --- a/imap/imap.h +++ b/imap/imap.h @@ -106,7 +106,7 @@ void imap_logout_all(void); /* util.c */ int imap_parse_path(const char *path, struct ConnAccount *account, char *mailbox, size_t mailboxlen); -void imap_pretty_mailbox(char *path, const char *folder); +void imap_pretty_mailbox(char *path, size_t pathlen, const char *folder); int imap_wait_keepalive(pid_t pid); void imap_keepalive(void); diff --git a/imap/util.c b/imap/util.c index 54923b8ff..a0e890a6d 100644 --- a/imap/util.c +++ b/imap/util.c @@ -679,12 +679,13 @@ int imap_mxcmp(const char *mx1, const char *mx2) /** * imap_pretty_mailbox - Prettify an IMAP mailbox name - * @param path Mailbox name to be tidied - * @param folder Path to use for '+' abbreviations + * @param path Mailbox name to be tidied + * @param pathlen Length of path + * @param folder Path to use for '+' abbreviations * * Called by mutt_pretty_mailbox() to make IMAP paths look nice. */ -void imap_pretty_mailbox(char *path, const char *folder) +void imap_pretty_mailbox(char *path, size_t pathlen, const char *folder) { struct ConnAccount target_conn_account, home_conn_account; struct Url url; @@ -736,10 +737,7 @@ void imap_pretty_mailbox(char *path, const char *folder) fallback: mutt_account_tourl(&target_conn_account, &url); url.path = target_mailbox; - /* FIXME: That hard-coded constant is bogus. But we need the actual - * size of the buffer from mutt_pretty_mailbox. And these pretty - * operations usually shrink the result. Still... */ - url_tostring(&url, path, 1024, 0); + url_tostring(&url, path, pathlen, 0); } /** diff --git a/muttlib.c b/muttlib.c index 8d6253e94..7ed721088 100644 --- a/muttlib.c +++ b/muttlib.c @@ -613,7 +613,7 @@ void mutt_pretty_mailbox(char *buf, size_t buflen) if ((scheme == U_IMAP) || (scheme == U_IMAPS)) { - imap_pretty_mailbox(buf, C_Folder); + imap_pretty_mailbox(buf, buflen, C_Folder); return; } -- 2.49.0