From 01cdccc24109aeac61fd26ac049c116a2c5cadfb Mon Sep 17 00:00:00 2001 From: "Torrance, Douglas" Date: Wed, 13 Feb 2019 02:18:43 +0000 Subject: [PATCH] wmbiff: handle EAGAIN or GNUTLS_E_AGAIN From Debian bug #917467, reported by Nye Liu [1]: If gnutls_read() or read() report EAGAIN, tlscomm_expect() fails: wmbiff/nyet comm: wrote a000 CAPABILITY wmbiff/nyet comm: imap.***.***:993: expecting: * CAPABILITY wmbiff/nyet comm: imap.***.***:993: gnutls error reading: Resource temporarily unavailable, try again. wmbiff/nyet imap4: unable to query capability stringwmbiff/nyet comm: wrote a002 LOGOUT wmbiff/nyet comm: imap.***.***:993: closing. [1] https://bugs.debian.org/917467 --- wmbiff/wmbiff/Imap4Client.c | 2 +- wmbiff/wmbiff/tlsComm.c | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/wmbiff/wmbiff/Imap4Client.c b/wmbiff/wmbiff/Imap4Client.c index ba12a66..ea24dd9 100644 --- a/wmbiff/wmbiff/Imap4Client.c +++ b/wmbiff/wmbiff/Imap4Client.c @@ -258,7 +258,7 @@ FILE *imap_open(Pop3 pc) encrypted session. */ tlscomm_printf(scs, "a000 CAPABILITY\r\n"); if (tlscomm_expect(scs, "* CAPABILITY", capabilities, BUF_SIZE) == 0) { - IMAP_DM(pc, DEBUG_ERROR, "unable to query capability string"); + IMAP_DM(pc, DEBUG_ERROR, "unable to query capability string\n"); goto communication_failure; } diff --git a/wmbiff/wmbiff/tlsComm.c b/wmbiff/wmbiff/tlsComm.c index 85426a0..f37f3f5 100644 --- a/wmbiff/wmbiff/tlsComm.c +++ b/wmbiff/wmbiff/tlsComm.c @@ -229,10 +229,12 @@ tlscomm_expect(struct connection_state *scs, #ifdef USE_GNUTLS if (scs->tls_state) { /* BUF_SIZE - 1 leaves room for trailing \0 */ - thisreadbytes = - gnutls_read(scs->tls_state, - &scs->unprocessed[buffered_bytes], - BUF_SIZE - 1 - buffered_bytes); + do { + thisreadbytes = + gnutls_read(scs->tls_state, + &scs->unprocessed[buffered_bytes], + BUF_SIZE - 1 - buffered_bytes); + } while (thisreadbytes == GNUTLS_E_AGAIN); if (thisreadbytes < 0) { handle_gnutls_read_error(thisreadbytes, scs); return 0; @@ -240,9 +242,11 @@ tlscomm_expect(struct connection_state *scs, } else #endif { - thisreadbytes = - read(scs->sd, &scs->unprocessed[buffered_bytes], - BUF_SIZE - 1 - buffered_bytes); + do { + thisreadbytes = + read(scs->sd, &scs->unprocessed[buffered_bytes], + BUF_SIZE - 1 - buffered_bytes); + } while (thisreadbytes == EAGAIN); if (thisreadbytes < 0) { TDM(DEBUG_ERROR, "%s: error reading: %s\n", scs->name, strerror(errno)); -- 2.11.4.GIT