From 22fc69bb8d419968aa52e79f21bef8bee73beb06 Mon Sep 17 00:00:00 2001 From: Brendan Cully Date: Mon, 2 Apr 2007 14:33:29 -0700 Subject: [PATCH] Fix a segfault in the new mboxcache hcache lookup. idata may not have an associated context, so the cache path must use the account info instead. For harmony with the other hcache callers, make them all canonify the path the same way with imap_hcache_open. --- imap/imap.c | 11 ++++------- imap/imap_private.h | 4 ++++ imap/message.c | 2 +- imap/util.c | 19 +++++++++++++++++++ 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/imap/imap.c b/imap/imap.c index 25bf0472..ff939c1c 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -251,8 +251,8 @@ void imap_expunge_mailbox (IMAP_DATA* idata) #if USE_HCACHE header_cache_t *hc; char uidbuf[32]; - - hc = mutt_hcache_open (HeaderCache, idata->ctx->path); + + hc = imap_hcache_open (idata, idata->ctx->path); #endif for (i = 0; i < idata->ctx->msgcount; i++) @@ -1157,7 +1157,7 @@ int imap_sync_mailbox (CONTEXT* ctx, int expunge, int* index_hint) #if USE_HCACHE if (expunge && ctx->closing) - hc = mutt_hcache_open (HeaderCache, idata->ctx->path); + hc = imap_hcache_open (idata, idata->ctx->path); #endif /* save messages with real (non-flag) changes */ @@ -1582,7 +1582,6 @@ IMAP_STATUS* imap_mboxcache_get (IMAP_DATA* idata, const char* mbox, int create) char urlstr[LONG_STRING]; unsigned int *uidvalidity = NULL; unsigned int *uidnext = NULL; - char* path; #endif for (cur = idata->mboxcache; cur; cur = cur->next) @@ -1606,11 +1605,9 @@ IMAP_STATUS* imap_mboxcache_get (IMAP_DATA* idata, const char* mbox, int create) } #ifdef USE_HCACHE - path = safe_strdup (idata->ctx->path); - url_parse_ciss (&url, path); + mutt_account_tourl (&idata->conn->account, &url); url.path = (char*)mbox; url_ciss_tostring (&url, urlstr, sizeof (urlstr), 0); - FREE (&path); hc = mutt_hcache_open (HeaderCache, urlstr); if (hc) { diff --git a/imap/imap_private.h b/imap/imap_private.h index c7a6b876..cf038599 100644 --- a/imap/imap_private.h +++ b/imap/imap_private.h @@ -264,6 +264,10 @@ char* imap_set_flags (IMAP_DATA* idata, HEADER* h, char* s); int imap_cache_del (IMAP_DATA* idata, HEADER* h); /* util.c */ +#ifdef USE_HCACHE +void* imap_hcache_open (IMAP_DATA* idata, const char* path); +#endif + int imap_continue (const char* msg, const char* resp); void imap_error (const char* where, const char* msg); IMAP_DATA* imap_new_idata (void); diff --git a/imap/message.c b/imap/message.c index 5f997418..51ed354d 100644 --- a/imap/message.c +++ b/imap/message.c @@ -122,7 +122,7 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend) #if USE_HCACHE if (!msgbegin) - hc = mutt_hcache_open (HeaderCache, ctx->path); + hc = imap_hcache_open (idata, ctx->path); if (hc) { diff --git a/imap/util.c b/imap/util.c index b2e85dfc..1af5a890 100644 --- a/imap/util.c +++ b/imap/util.c @@ -66,6 +66,25 @@ int imap_expand_path (char* path, size_t len) return rc; } +#ifdef USE_HCACHE +void* imap_hcache_open (IMAP_DATA* idata, const char* path) +{ + IMAP_MBOX mx; + ciss_url_t url; + char cachepath[LONG_STRING]; + + if (imap_parse_path (path, &mx) < 0) + return NULL; + + mutt_account_tourl (&idata->conn->account, &url); + url.path = mx.mbox; + url_ciss_tostring (&url, cachepath, sizeof (cachepath), 0); + FREE (&mx.mbox); + + return mutt_hcache_open (HeaderCache, cachepath); +} +#endif + /* imap_parse_path: given an IMAP mailbox name, return host, port * and a path IMAP servers will recognise. * mx.mbox is malloc'd, caller must free it */ -- 2.40.0