Kevin McCarthy [Wed, 2 Mar 2016 23:08:49 +0000 (15:08 -0800)]
Add hard redraw for the gpgme application/pgp handler.
Will Yardley reported display artifacts and keyboard issues after
decrypting a traditional pgp message using gpgme. It turns out the
gpgpme code path was missing a hard_redraw() to repaint the screen
after pinentry.
Kevin McCarthy [Tue, 16 Feb 2016 03:44:23 +0000 (19:44 -0800)]
Add $pgp_decryption_okay to verify multipart/encrypted are actually encrypted. (closes #3770)
In pgp classic mode, if the $pgp_decrypt_command generated output, it
assumed the content was encrypted. However, gpg will generate output
even if the block is simply signed and armored text. The problem is
that mutt was then printing mime headers labelling the output as
encrypted text in the ui.
Add a new option, and suggested value of:
set pgp_decryption_okay="^\\[GNUPG:\\] DECRYPTION_OKAY"
If set, the output from the decrypt command will be scanned for this
regexp to confirm an actual decryption occurred.
Note that gpgme already correctly rejects this form of spoofed message.
Kevin McCarthy [Sun, 7 Feb 2016 18:15:27 +0000 (10:15 -0800)]
Fix pgp and smime decryption in mutt_prepare_template().
Change the "combined" multipart decryption block to only work for pgp,
since mutt_is_multipart_encrypted() currently only checks for pgp
headers and it therefore only worked for pgp in the first place.
Fix the newhdr->security to be based on what that function returns,
instead of the "context" hdr passed in.
Add a smime decryption block below when iterating through the content.
Fix the application/pgp decryption block to assign to hdr->security
using the type of the app/pgp part instead of hdr->content.
Kevin McCarthy [Sat, 23 Jan 2016 20:30:16 +0000 (12:30 -0800)]
Increase HUGE_STRING size to 8192. (see #3804)
The interface for editing a large number of recipients is poor and
perhaps shouldn't be using a fixed buffer size. Until a redesign can
be thought about, this will help.
Kevin McCarthy [Tue, 19 Jan 2016 22:05:52 +0000 (14:05 -0800)]
Make sasl authentication buffers dynamically sized. (see #3804)
The reporter found that the current buffer of HUGE_STRING was
insufficient in his case to encode the clientout response back to the
server in imap_auth_sasl().
Since sasl gives us the size of "clientout", we can dynamically malloc
and resize the buffer as needed. This patch uses max(LONG_STRING,
(clientoutlen*2)). This is sufficient to hold the base64 encoded
value plus additional prefix/suffix needed in each protocol.
The size is rechecked after each sasl_client_step() and resized as
needed.
Similar code is in pop_auth_sasl() and smtp_auth_sasl(), so convert
all three to use a dynamic buffer.
Kevin McCarthy [Wed, 6 Jan 2016 02:08:07 +0000 (18:08 -0800)]
Allow tab as a delimiter in smime .index files. (closes #3802)
The old parsing code used fscanf, and so happened to allow a tab as a
delimiter. Even though smime_keys.pl uses a space, some users
maintain their own .index files by hand (using tab delimiters), so
continue to allow that delimiter.
Kevin McCarthy [Tue, 5 Jan 2016 00:28:56 +0000 (16:28 -0800)]
Add a couple missing ATTACHPTR->tree frees.
While working on ticket 3800, I noticed the tree wasn't being freed
inside OP_COMPOSE_EDIT_HEADERS. Add a free there, and in the cleanup
at the end of mutt_compose_menu().
A few other sections in mutt_compose_menu() are performing a
free-on-error where the tree isn't allocated yet, so skip it for
those.
I believe this is actually not fixing a memory leak: all attachments
are always at level 0 in the compose menu (as far as I know); so
nothing is ever allocated in the tree pointer. However since other
parts of the code in compose.c clean this up, it make sense to add
them here too.
S. Gilles [Mon, 4 Jan 2016 21:57:40 +0000 (13:57 -0800)]
Prefer bright versions (8-15) of colors for brightXXX backgrounds.
When a bright color is specified as a background, try to use the
bright version of that color, falling back to the A_BLINK method only
on terms which do not support enough colors.
Kevin McCarthy [Fri, 1 Jan 2016 20:24:53 +0000 (12:24 -0800)]
Use strrchr to search for Received date separator. (closes #3798)
Sample email provided by the submitter showed a Received header with a
";" at the end of each line, instead of a single ";" in front of the
date. The emails are obviously not RFC compliant, but the fix is
simple enough: find the last ";" using strrchr instead of the first.
Kevin McCarthy [Fri, 1 Jan 2016 20:07:46 +0000 (12:07 -0800)]
Convert copyright years to all use 4 digit years.
Vincent Lefèvre pointed out the common shortcut, e.g 1996-9, is
actually not allowed for copyright years. Convert all the copyright
years (for mutt files) to use 4 digits.
Kevin McCarthy [Fri, 1 Jan 2016 20:07:40 +0000 (12:07 -0800)]
Update copyright notices.
This patch only updates existing copyright notices in the source
files, using commit dates since the last copyright update in commits e3af935cdb1a and f8fd60d8d3f2.
Add a notice to the COPYRIGHT file to refer to our mercurial
repository for the full commit history.
Add myself to the COPYRIGHT file and smime_keys.pl file.
Kevin McCarthy [Fri, 1 Jan 2016 17:48:51 +0000 (09:48 -0800)]
Fix segfault when deleting and reusing attachment slots. (closes #3800)
When attachments are deleted, delete_attachment() slides the entries
down in the idx array, but forgets to NULL out the last vacated slot.
If more attachments are added later on via OP_COMPOSE_EDIT_HEADERS and
the Attach: pseudo-header, mutt_gen_attach_list() will attempt to
re-use the ATTACHPTR in that last slot because it wasn't set to NULL.
This will be pointing to freed memory and likely segfault (at best).
Kevin McCarthy [Tue, 8 Dec 2015 17:11:30 +0000 (09:11 -0800)]
Fix hash table key "use after free" in mh_check_mailbox(). (closes #3797)
The fnames hash uses the maildir->header->path as the key. As matches
are found, the headers are freed. This inadvertantly also freed the key
to the hashtable entry; the next hash_find() going to the same bucket
might end up comparing keys with a freed string.
This patch stores the path in the struct maildir canon_fname field (just
as maildir_check_mailbox() does) and uses that as the hash key instead.
This field isn't used outside of maildir_check_mailbox(), and is
automatically freed for us in the maildir_move_to_context() call at the
bottom of both functions.
Note there are other ways to fix this problem:
- Add a new mode to the hash table, causing it to strdup the keys and
free them itself.
- Delete the entries in the fnames hash, rather leaving them there.
The first seems the cleanest, but would end up touching much more code.
The second is also clean, but might have a negative performance impact.
Additionally, peeking back in history to changeset 1d45a50b6f9b, it
looks like the canon_fname used to be used by mh too, so perhaps
removing the strdup may have been a mistake during refactoring at some
point.
Kevin McCarthy [Thu, 3 Dec 2015 23:23:34 +0000 (15:23 -0800)]
Provide a better prompt and error for inline PGP with attachments. (closes #3738)
Change mutt_protect() to check for text/plain before trying to invoke
crypt_pgp_traditional_encryptsign(). This way, mutt can provide a bit
more specific prompt and error message.
Since pgp_mime_auto says it will prompt in the event of any failure,
keep the more generic prompt after the encryptsign call too.
Kevin McCarthy [Wed, 2 Dec 2015 02:20:27 +0000 (18:20 -0800)]
Loosen mutt_signed_handler() protocol value consistency check. (closes #3639)
Apparently, for S/MIME, some MUAs mismatch the protocol value of
the multipart/signed and the content-type of the signature: putting
"pkcs7-signature" in one and "x-pkcs7-signature" in the other.
Change mutt_signed_handler() to independently verify the values of the
protocol and the content-type. This still checks for correct values but
doesn't ensure they match between the two (for S/MIME).
Kevin McCarthy [Mon, 30 Nov 2015 23:52:30 +0000 (15:52 -0800)]
smime: allow signing message digest algorithm to be specified.
Currently, Mutt hardcodes micalg=sha1 for signed messages.
Unfortunately, the actual message digest algorithm used defaults to
the value in the "Signature Algorithm" field in the signing key's
certificate.
Add a new configuration option $smime_sign_digest_alg, defaulting
to sha256. Add a new printf format string, %d, to be used in the
signing command to specify the digest algorithm. Modify the sample
$smime_sign_command to include "-md %d".
Note: This solution requires using the modified $smime_sign_command,
or else the micalg parameter again may not match the algorithm used.
An alternative solution would be to query the certificate "Signature
Algorithm" field and try to change the micalg to match it, but this
method is easier to implement and provides better control for the user
to configure, in any case.
Kevin McCarthy [Thu, 26 Nov 2015 19:01:19 +0000 (11:01 -0800)]
Clean up address_uses_unicode() (closes #3794)
Pull the null check out of the loop. Use a bit comparison to detect if
the high bit is set: this avoids a warning for platforms where char is
implicitly signed (where comparing < 128 is always true).
Kevin McCarthy [Wed, 25 Nov 2015 05:45:58 +0000 (21:45 -0800)]
Fix bad idn error on local mailboxes. (closes #3795)
Commit 831abf39d53a pulled the mbox_to_udomain() call inside the
conversion functions. Unfortunately, this causes local (user only)
mailboxes to be considered conversion errors instead of just skipping
them.
Revert mbox_to_udomain() back to using a static buffer and pull back
into the mutt_addrlist_to_local/intl() functions.
Pass the user and domain into the conversion functions instead of the address.
Kevin McCarthy [Tue, 24 Nov 2015 23:49:26 +0000 (15:49 -0800)]
Rename idna functions and bits for smtputf8 changes.
This is patch 1 of 4 implementing support for SMTPUTF8 (RFC 6531).
Change mutt_idna.c to be always compiled. Remove the stub functions in
mutt_idna.h. Instead, put #ifdefs around the idna function calls. The
conversion functions will be fixed up in the next patch.
Rename the conversion functions to mutt_addrlist_to_intl() and
mutt_env_to_intl(). Rename the ADDRESS idna status bits to "intl"
status bits.
Kevin McCarthy [Sat, 21 Nov 2015 23:28:57 +0000 (15:28 -0800)]
Remove redundant mbox delimiter check in imap_browse(). (closes #3646)
imap_fix_path() removes duplicate and trailing delimiters, so the check
below it was redundant. This also made it appear list.delim could be
used uninitialized.
Remove the check, but add a check to make sure the "fixed" path has
len>0, to prevent oob accesses of mbox[n-1] below.
Lastly, remove a redundant n=strlen(mbox) inside the initial LIST
processing loop. The mbox isn't changed from above, so there is no
need to rerun strlen.
Kevin McCarthy [Tue, 10 Nov 2015 02:53:05 +0000 (18:53 -0800)]
Improve error messages for eat_date() and eat_regexp().
After calling mutt_extract_token(), s->dptr will typically be at the end
of the string if an error occurred. Save a pointer to the beginning of
the expression, so it can be properly displayed in the error message.
Convert eat_date() and eat_regexp() to use the same iconv strings for
the error message.
Kevin McCarthy [Mon, 9 Nov 2015 23:40:42 +0000 (15:40 -0800)]
Fix possible unintentional '\0' strchr matches.
After fixing the ticket 3787 strchr issue, this patch cleans up other
potentially incorrect uses of strchr for the '\0' case.
In mutt_multi_choice(), mutt_getch() can technically return 0. Although
it seems the user would have to try quite hard to do this, it's
incorrect to return that index into letters. Change "ch.ch==0" to be
considered the same as an abort.
is_email_wsp() is used in a couple places where it wasn't obvious
whether '\0' was being accounted for, so add an explicit check to the
function.
Inside eat_date(), if mutt_extract_token() had no input and returned
"", the strchr ("<>=", buffer.data[0]) below would return a pointer.
In actuality, this is prevented by an empty parameter check inside
mutt_pattern_comp(), but it doesn't hurt to make it the same as
eat_regexp() and have the check explicitly done here too.
rfc2047_encode() was another borderline case for adding a check. The
convert_string() sets a length, so it seems highly unlikely that *t
could be 0, but doesn't hurt to add the check.
The find_encoded_word() fix looks necessary. If the passed in s was
something like "=?charset?" (followed by EOS, '\0'), the strchr("BbQq",
q[1]) would in fact return a pointer and the following q[2] would read
past the end of string. If q[2] happened to be '?', it might even
continue reading in the for loop below.
Lastly, in parse_mailboxdomain(), the potential overread was already
fixed in changeset:a6919571eb59, but although the nonspecial and special
strchr() line happens to "work" for the case of '\0', it's pretty
fragile to leave as is. It's better to be explicit and just return if
we hit EOS without calling next_token().
Kevin McCarthy [Sun, 18 Oct 2015 11:45:51 +0000 (19:45 +0800)]
Fix next_token() oob read. (closes #3787)
With specially crafted input to 'mutt -H', the line "Return-Path:<() "
is read and passed to mutt_parse_rfc822_line(). "<() " is then passed
through to rfc822_parse_adrlist().
Eventually, inside next_token(), is_special(*s) is called when s
points to the end of the string ('\0'). This macro calls strchr,
which will actually match and return a pointer to the trailing '\0' in
RFC822Specials! This causes "s + 1" to be returned, skipping past the
end of string inside parse_mailboxdomain().
This patch adds a check to make sure *s is non-null before calling
is_special(*s).
Kevin McCarthy [Sat, 17 Oct 2015 03:15:01 +0000 (11:15 +0800)]
Fix error message for attach-message. (closes #3785)
Currently if mx_open_mailbox() fails when trying to attach a message,
mutt_perror() is called. Change this to call mutt_error() instead,
since errno isn't set for all failure cases.
Kevin McCarthy [Sun, 4 Oct 2015 02:08:49 +0000 (10:08 +0800)]
Create a separate macro/push/exec event buffer. (closes #3779)
Currently, the SSL and TLS certficate prompts turn on
OPTUNBUFFEREDINPUT, (to prevent macros and such from running right
through the dialog). Unfortunately, the menu dialog processing in
menu_dialog_dokey() is using mutt_ungetch() to forward non-dialog keys
on to standard menu processing. With OPTUNBUFFEREDINPUT set, those keys
never make it to the menu and are buffered until after the menu dialog.
This patch creates a new event buffer, separate from the standard
"unget" buffer, for use by macros, exec, and push events. These events
can be temporarily ignored by setting OPTIGNOREMACROEVENTS (renamed
from OPTUNBUFFEREDINPUT), while continuing to allow unget events to be
processed.
Since the "push" and "unget" functions now go to different buffers,
function names were slightly renamed, to make it less easy to
unintentionally use the wrong function at the wrong time.
Kevin McCarthy [Sun, 4 Oct 2015 02:08:45 +0000 (10:08 +0800)]
Fix menu type in certificate prompt. (see #3779)
The menu type is used in several places as a direct index into
Keymaps[], so passing in -1 to mutt_new_menu() was leading to illegal
memory accesses later on.
Add a range check in mutt_new_menu(), defaulting to MENU_GENERIC, to
prevent this problem in the future.
Kevin McCarthy [Wed, 30 Sep 2015 03:25:28 +0000 (11:25 +0800)]
Fix chomp in smime_handle_cert_email.
During a review of the previous patch, Oswald Buddenhagen noticed two
of the fixed oob reads had another problem: they were "chomping" (the
newline) without verifying there actually was a newline at the end of
the string.
Kevin McCarthy [Wed, 30 Sep 2015 03:21:06 +0000 (11:21 +0800)]
Fix oob reads when fgets returns "\0". (closes #3776)
The ticket reported an out of bounds read in mutt_read_rfc822_line()
when a '\0' was embedded on its own line in the headers. The function
assumed if fgets() didn't return NULL, then the string would have at
least one character.
I scanned the rest of the code and found three other places making the
same assumption for fgets.
Thanks to hanno for finding this with the "american fuzzy lop" tool.
Kevin McCarthy [Sun, 6 Sep 2015 23:31:57 +0000 (16:31 -0700)]
Fix double-decode during IMAP browse.
cmd_parse_list() already calls imap_unmunge_mbox_name() on the mailbox
names returned from the server. However, browse_add_list_result() was
taking those mailbox names and passing them to imap_add_folder(), which
was calling imap_unmunge_mbox_name() yet again.
The reason is that imap_browse() was directly calling imap_add_folder()
too, passing in a previously encoded "mbox" name. After looking
carefully at the code, I could find no reason that mbox needed to
be encoded outside of the LIST commands.. Therefore I changed
imap_browse() to call imap_munge_mbox_name() on mbox for the
two LIST commands generated from it instead, and removed the
imap_unmunge_mbox_name() call inside imap_add_folder().
Kevin McCarthy [Sun, 6 Sep 2015 14:40:06 +0000 (07:40 -0700)]
Fix use after free of ctx->last_tag. (closes #3775)
When using imap to access gmail, tagging and saving messages to "all
mail" and pressing <sync-mailbox> can result in the call path:
mx_check_mailbox()
imap_check_mailbox()
imap_cmd_finish()
imap_expunge_mailbox()
mx_update_tables()
followed by:
mx_sync_mailbox()
The HEADER pointed to by ctx->last_tag will be removed and FREE'ed in
mx_update_tables(), but will subsequently be accessed in mx_sync_mailbox().
This patch simply sets ctx->last_tag=NULL if it is freed inside mx_update_tables().
Thanks to Peter Lekensteyn for the bug report and ASAN report.
Kevin McCarthy [Thu, 3 Sep 2015 01:11:28 +0000 (18:11 -0700)]
Add time_t conversion to fix gpgme segfault on OpenBSD.
time_t isn't the same size as gpgme_subkey_t->timestamp on OpenBSD.
Passing &subkey->timestamp to localtime was therefore passing an address
to the wrong size int and was causing a segfault.
Thanks to Hannes Wenzel for reporting the bug and providing a patch.
Kevin McCarthy [Mon, 17 Aug 2015 21:51:07 +0000 (14:51 -0700)]
Add idn to MUTTLIBS instead of LIBS (see #3638)
Currently, -lidn is included while linking all the mutt binaries. Add
it to MUTTLIBS instead so it's only used for the mutt linking.
Also, add $LIBICONV to $LIBS before checking for some of the idna
functions. On some sytems, there are apparently issues when using
static linking. (Thanks to grarpamp for reporting).
Kevin McCarthy [Mon, 17 Aug 2015 19:31:40 +0000 (12:31 -0700)]
Change mutt_adv_mktemp to call mutt_mktemp instead of mktemp. (see #3638).
mutt_mktemp is currently called in 95% of the cases in mutt, and
is already our "own rolled" version of mktemp. The "insecure mktemp
warning" discussion keeps coming up, so instead add prefix and suffix
functionality to mutt_mktemp() and call that.
All other uses of Tempdir in the mutt source did not call
mutt_expand_path() first, so remove that from mutt_adv_mktemp().
Kevin McCarthy [Wed, 29 Jul 2015 16:07:51 +0000 (09:07 -0700)]
Add error handling for ^ and other empty mailbox shortcuts.
(closes #2402) (closes #3735)
Explicitly mention the ^ example in the documentation added in 6d733cab6b45.
Add an error message for ^ when CurrentFolder is not set. Add checks
for other mailbox shortcuts that expand to the empty string. This
could happen if the @alias shortcut was accidentally used, or the value
referenced by a shortcut isn't set yet.
Kevin McCarthy [Mon, 27 Jul 2015 21:09:55 +0000 (14:09 -0700)]
Add "Mailbox Matching in Hooks" section to manual.
Folder-hook and mbox-hook perform mailbox shortcut expansion on the
regexp parameter. Add a section to the manual to give examples and make
the behavior clearer.
In certain circumstances, Exchange corrupts a multipart/encrypted block
into:
<multipart/mixed>
<text/plain>
<application/pgp-encrypted> [BASE64-encoded]
<application/octet-stream> [BASE64-encoded]
This patch pulls the full detection of valid/invalid multiparts
into mutt_body_handler(). It extracts a run_decode_and_handler()
function, which is reused by new intermediate handlers to decode
the application/octet-stream part before passing it directly to
crypt_pgp_encrypted_handler. These intermediate handlers then check
and set any GOODSIG flags back into the parent part.
This change may result in less error messages for invalid
multipart/encrypted parts. Instead, mutt will default to the
multipart_handler if it isn't fully "correct".
Viewing attachments uses crypt_pgp_decrypt_mime() which bypasses the
handler mechanism. Add decoding to the decrypt_mime() functions for pgp
and gpgme.
Thanks to Vincent Brillault for his analysis and initial patch.
Kevin McCarthy [Tue, 21 Jul 2015 19:34:49 +0000 (12:34 -0700)]
Imap: Fix flag caching after sync.
The flags cached in IMAP_HEADER_DATA were not updated to match the
HEADER flags after a sync. This means if a flag were toggled and synced
twice, the second sync was not sending the flag update.
Kevin McCarthy [Thu, 23 Jul 2015 21:57:04 +0000 (14:57 -0700)]
Fix compiler type warnings. (closes #3765)
The output of mutt_local_tz() was being passed to abs(). Technically
the return type is time_t, but it represents a small value: the timezone
offset in seconds. Add a safe explicit cast to int.
Change the txt parameter of mutt_make_help() to type const char *.
Typically all calls run the txt parameter through _(), which
accepts const char * and returns a char *. However, if NLS is not
enabled, _() is a noop, simply returning the parameter itself. In
mutt_compile_help(), items[i].name is const char *, so it will generate
a warning when passed as the txt parameter of mutt_make_help().
On some systems, e.g. OS X, snprintf is defined as a macro. One call
in hcache.c was embedding directives inside the snprintf call. This is
apparently undefined behavior, so duplicate the call instead.
Kevin McCarthy [Thu, 9 Jul 2015 21:50:05 +0000 (14:50 -0700)]
Use $(VAR) instead of @VAR@ in Makefile.am files. (closes #3664)
The @VAR@ form is not overridable, such as the case for #3664 where the
reporter wanted to override DOTLOCK_GROUP.
It's doubtful targets need to be overriden, but it makes sense to be
consistent in the usage of automake substituted variables unless there
is a particular reason/bug to work around.
Kevin McCarthy [Thu, 2 Jul 2015 18:21:19 +0000 (11:21 -0700)]
Convert from using mkinstalldirs to $(MKDIR_P).
The automake mkinstalldirs script is now deprecated. "install-sh -d"
can be used in place. Configure.ac already includes AC_PROG_INSTALL,
which will ensure install-sh is bundled. Add AC_PROG_MKDIR_P, which
will set $(MKDIR_P) to either a thread-safe "mkdir -p" or will fall back
to using install-sh.