From: Kevin McCarthy Date: Tue, 8 Oct 2019 03:24:38 +0000 (+0800) Subject: Convert imap_cachepath() and callers to use buffers. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f055ff5464366d51e6903552ab9b98fe021b92cb;p=mutt Convert imap_cachepath() and callers to use buffers. --- diff --git a/imap/imap_private.h b/imap/imap_private.h index 67376d2b..88af5a48 100644 --- a/imap/imap_private.h +++ b/imap/imap_private.h @@ -314,8 +314,7 @@ IMAP_DATA* imap_new_idata (void); void imap_free_idata (IMAP_DATA** idata); char* imap_fix_path (IMAP_DATA* idata, const char* mailbox, char* path, size_t plen); -void imap_cachepath(IMAP_DATA* idata, const char* mailbox, char* dest, - size_t dlen); +void imap_cachepath(IMAP_DATA *idata, const char *mailbox, BUFFER *dest); int imap_get_literal_count (const char* buf, unsigned int* bytes); char* imap_get_qualifier (char* buf); int imap_mxcmp (const char* mx1, const char* mx2); diff --git a/imap/message.c b/imap/message.c index b2c079e5..314961c5 100644 --- a/imap/message.c +++ b/imap/message.c @@ -1471,14 +1471,18 @@ out: static body_cache_t *msg_cache_open (IMAP_DATA *idata) { - char mailbox[_POSIX_PATH_MAX]; + BUFFER *mailbox; + body_cache_t *rv; if (idata->bcache) return idata->bcache; - imap_cachepath (idata, idata->mailbox, mailbox, sizeof (mailbox)); + mailbox = mutt_buffer_pool_get (); + imap_cachepath (idata, idata->mailbox, mailbox); + rv = mutt_bcache_open (&idata->conn->account, mutt_b2s (mailbox)); + mutt_buffer_pool_release (&mailbox); - return mutt_bcache_open (&idata->conn->account, mailbox); + return rv; } static FILE* msg_cache_get (IMAP_DATA* idata, HEADER* h) diff --git a/imap/util.c b/imap/util.c index 42f07cc2..c529fd8f 100644 --- a/imap/util.c +++ b/imap/util.c @@ -139,32 +139,43 @@ header_cache_t* imap_hcache_open (IMAP_DATA* idata, const char* path) { IMAP_MBOX mx; ciss_url_t url; - char cachepath[LONG_STRING]; - char mbox[LONG_STRING]; + BUFFER *cachepath = NULL; + BUFFER *mbox = NULL; size_t len; + header_cache_t *rv = NULL; + + mbox = mutt_buffer_pool_get (); + cachepath = mutt_buffer_pool_get (); if (path) - imap_cachepath (idata, path, mbox, sizeof (mbox)); + imap_cachepath (idata, path, mbox); else { if (!idata->ctx || imap_parse_path (idata->ctx->path, &mx) < 0) - return NULL; + goto cleanup; - imap_cachepath (idata, mx.mbox, mbox, sizeof (mbox)); + imap_cachepath (idata, mx.mbox, mbox); FREE (&mx.mbox); } - if (strstr(mbox, "/../") || (strcmp(mbox, "..") == 0) || (strncmp(mbox, "../", 3) == 0)) - return NULL; - len = strlen(mbox); - if ((len > 3) && (strcmp(mbox + len - 3, "/..") == 0)) - return NULL; + if (strstr (mutt_b2s (mbox), "/../") || + (strcmp (mutt_b2s (mbox), "..") == 0) || + (strncmp(mutt_b2s (mbox), "../", 3) == 0)) + goto cleanup; + len = mutt_buffer_len (mbox); + if ((len > 3) && (strcmp(mutt_b2s (mbox) + len - 3, "/..") == 0)) + goto cleanup; mutt_account_tourl (&idata->conn->account, &url); - url.path = mbox; - url_ciss_tostring (&url, cachepath, sizeof (cachepath), U_PATH); + url.path = mbox->data; + url_ciss_tobuffer (&url, cachepath, U_PATH); - return mutt_hcache_open (HeaderCache, cachepath, imap_hcache_namer); + rv = mutt_hcache_open (HeaderCache, mutt_b2s (cachepath), imap_hcache_namer); + +cleanup: + mutt_buffer_pool_release (&mbox); + mutt_buffer_pool_release (&cachepath); + return rv; } void imap_hcache_close (IMAP_DATA* idata) @@ -548,30 +559,27 @@ char *imap_fix_path (IMAP_DATA *idata, const char *mailbox, char *path, return path; } -void imap_cachepath(IMAP_DATA* idata, const char* mailbox, char* dest, - size_t dlen) +void imap_cachepath (IMAP_DATA *idata, const char *mailbox, BUFFER *dest) { - char* s; - const char* p = mailbox; + const char *p = mailbox; - for (s = dest; p && *p && dlen; dlen--) + mutt_buffer_clear (dest); + if (!p) + return; + + while (*p) { if (*p == idata->delim) { - *s = '/'; + mutt_buffer_addch (dest, '/'); /* simple way to avoid collisions with UIDs */ if (*(p + 1) >= '0' && *(p + 1) <= '9') - { - if (--dlen) - *++s = '_'; - } + mutt_buffer_addch (dest, '_'); } else - *s = *p; + mutt_buffer_addch (dest, *p); p++; - s++; } - *s = '\0'; } /* imap_get_literal_count: write number of bytes in an IMAP literal into