I ran into a segfault in mutt where it re-used an already closed
SSL connection object. imap_cmd_start() closes the connection
internally if an error occurs. Backtrace from gdb included below.
This adds missing error checks to prevent such crashes.
diff acfb5fb02fb4eeed46d4f8c7f0da28d4f913acba /usr/ports
blob - 2e5834519dfd38ad7a30866f7a60f1939be0be03
file + mail/mutt/Makefile
--- mail/mutt/Makefile
+++ mail/mutt/Makefile
@@ -4,6 +4,7 @@ COMMENT= tty-based e-mail client
DISTNAME= mutt-1.13.2
EPOCH= 3
+REVISION= 0
CATEGORIES= mail
HOMEPAGE= http://www.mutt.org/
blob - /dev/null
file + mail/mutt/patches/patch-imap_imap_c
--- mail/mutt/patches/patch-imap_imap_c
+++ mail/mutt/patches/patch-imap_imap_c
@@ -0,0 +1,64 @@
+$OpenBSD$
+
+check for errors during imap_cmd_start() to prevent segfaults
+
+(gdb) bt
+#0 ssl_socket_poll (conn=0x129aac94f000, wait_secs=60) at mutt_ssl.c:468
+#1 0x00001297d7fedfbb in imap_logout (idata=0x129aac94f288) at imap.c:905
+#2 0x00001297d7fedf4d in imap_logout_all () at imap.c:197
+#3 0x00001297d7f7ae1f in main (argc=<optimized out>, argv=<optimized out>, environ=<optimized out>) at main.c:1383
+(gdb) list 468
+463
+464 static int ssl_socket_poll (CONNECTION* conn, time_t wait_secs)
+465 {
+466 sslsockdata *data = conn->sockdata;
+467
+468 if (SSL_has_pending (data->ssl))
+469 return 1;
+470 else
+471 return raw_socket_poll (conn, wait_secs);
+472 }
+(gdb) p conn->fd
+$6 = -1
+(gdb) p conn->sockdata
+$7 = (void *) 0x0
+
+Index: imap/imap.c
+--- imap/imap.c.orig
++++ imap/imap.c
+@@ -696,7 +696,8 @@ static int imap_open_mailbox (CONTEXT* ctx)
+
+ idata->state = IMAP_SELECTED;
+
+- imap_cmd_start (idata, bufout);
++ if (imap_cmd_start (idata, bufout) == -1)
++ goto fail;
+
+ status = imap_mboxcache_get (idata, idata->mailbox, 1);
+
+@@ -900,7 +901,11 @@ void imap_logout (IMAP_DATA** idata)
+ /* we set status here to let imap_handle_untagged know we _expect_ to
+ * receive a bye response (so it doesn't freak out and close the conn) */
+ (*idata)->status = IMAP_BYE;
+- imap_cmd_start (*idata, "LOGOUT");
++ if (imap_cmd_start (*idata, "LOGOUT") == -1)
++ {
++ imap_free_idata (idata);
++ return;
++ }
+ if (ImapPollTimeout <= 0 ||
+ mutt_socket_poll ((*idata)->conn, ImapPollTimeout) != 0)
+ {
+@@ -2201,7 +2206,11 @@ int imap_complete(char* dest, size_t dlen, const char*
+ snprintf (buf, sizeof(buf), "%s \"\" \"%s%%\"",
+ option (OPTIMAPLSUB) ? "LSUB" : "LIST", list);
+
+- imap_cmd_start (idata, buf);
++ if (imap_cmd_start (idata, buf) == -1)
++ {
++ FREE (&mx.mbox);
++ return -1;
++ }
+
+ /* and see what the results are */
+ strfcpy (completion, NONULL(mx.mbox), sizeof(completion));
No comments:
Post a Comment