From: William Pettersson Date: Sun, 30 Jul 2017 04:59:38 +0000 (+1000) Subject: Encode URIs created with nm_uri_from_query X-Git-Tag: neomutt-20170907~47 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=refs%2Fpull%2F692%2Fhead;p=neomutt Encode URIs created with nm_uri_from_query Uses url_pct_encode to do the encoding. Note that url_pct_encode now also encodes the ampersand, which shouldn't cause problems given that it's only used for usernames and passwords otherwise. Addresses issue #603 --- diff --git a/mutt_notmuch.c b/mutt_notmuch.c index fca5bac8b..9533d7d88 100644 --- a/mutt_notmuch.c +++ b/mutt_notmuch.c @@ -1841,16 +1841,25 @@ char *nm_uri_from_query(struct Context *ctx, char *buf, size_t bufsz) mutt_debug(2, "nm_uri_from_query (%s)\n", buf); struct NmCtxData *data = get_ctxdata(ctx); char uri[_POSIX_PATH_MAX + LONG_STRING + 32]; /* path to DB + query + URI "decoration" */ + int added; if (data) - snprintf(uri, sizeof(uri), "notmuch://%s?query=%s", get_db_filename(data), buf); + added = snprintf(uri, sizeof(uri), "notmuch://%s?query=", get_db_filename(data)); else if (NotmuchDefaultUri) - snprintf(uri, sizeof(uri), "%s?query=%s", NotmuchDefaultUri, buf); + added = snprintf(uri, sizeof(uri), "%s?query=", NotmuchDefaultUri); else if (Maildir) - snprintf(uri, sizeof(uri), "notmuch://%s?query=%s", Maildir, buf); + added = snprintf(uri, sizeof(uri), "notmuch://%s?query=", Maildir); else return NULL; + if (added >= sizeof(uri)) + { + // snprintf output was truncated, so can't create URI + return NULL; + } + + url_pct_encode(&uri[added], sizeof(uri) - added, buf); + strncpy(buf, uri, bufsz); buf[bufsz - 1] = '\0'; diff --git a/url.c b/url.c index eb6100544..5d827c63d 100644 --- a/url.c +++ b/url.c @@ -186,7 +186,7 @@ int url_parse_ciss(struct CissUrl *ciss, char *src) return ciss_parse_userhost(ciss, tmp); } -static void url_pct_encode(char *dst, size_t l, const char *src) +void url_pct_encode(char *dst, size_t l, const char *src) { static const char *alph = "0123456789ABCDEF"; @@ -194,7 +194,7 @@ static void url_pct_encode(char *dst, size_t l, const char *src) l--; while (src && *src && l) { - if (strchr("/:%", *src) && l > 3) + if (strchr("/:&%", *src) && l > 3) { *dst++ = '%'; *dst++ = alph[(*src >> 4) & 0xf]; diff --git a/url.h b/url.h index d7332a770..1940d1ca2 100644 --- a/url.h +++ b/url.h @@ -67,5 +67,6 @@ int url_parse_ciss(struct CissUrl *ciss, char *src); int url_ciss_tostring(struct CissUrl *ciss, char *dest, size_t len, int flags); int url_parse_mailto(struct Envelope *e, char **body, const char *src); int url_pct_decode(char *s); +void url_pct_encode(char *dest, size_t len, const char *src); #endif /* _MUTT_URL_H */