From 5aa2a7ea41d7137640cb0914807fd1202b920543 Mon Sep 17 00:00:00 2001 From: Quantomicus Date: Mon, 17 Dec 2018 17:26:29 +0100 Subject: [PATCH] Fix s_client hang on non-compliant NNTP server test Fixes #7722 CLA: trivial Signed-off-by: Mateja Milosevic Reviewed-by: Paul Yang Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/7915) --- apps/s_client.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/apps/s_client.c b/apps/s_client.c index 8bdfbb65f1..51001d5766 100644 --- a/apps/s_client.c +++ b/apps/s_client.c @@ -2535,12 +2535,16 @@ int s_client_main(int argc, char **argv) /* STARTTLS command requires CAPABILITIES... */ BIO_printf(fbio, "CAPABILITIES\r\n"); (void)BIO_flush(fbio); - /* wait for multi-line CAPABILITIES response */ - do { - mbuf_len = BIO_gets(fbio, mbuf, BUFSIZZ); - if (strstr(mbuf, "STARTTLS")) - foundit = 1; - } while (mbuf_len > 1 && mbuf[0] != '.'); + BIO_gets(fbio, mbuf, BUFSIZZ); + /* no point in trying to parse the CAPABILITIES response if there is none */ + if (strstr(mbuf, "101") != NULL) { + /* wait for multi-line CAPABILITIES response */ + do { + mbuf_len = BIO_gets(fbio, mbuf, BUFSIZZ); + if (strstr(mbuf, "STARTTLS")) + foundit = 1; + } while (mbuf_len > 1 && mbuf[0] != '.'); + } (void)BIO_flush(fbio); BIO_pop(fbio); BIO_free(fbio); -- 2.39.2