From 8670f5da240e65412c83281305b01075974de218 Mon Sep 17 00:00:00 2001 From: Marc Hoersken Date: Fri, 26 Dec 2014 13:31:26 +0100 Subject: [PATCH] pem.c: make sure there's a trailing zero and b64data is not NULL ... if there is no base64 data between PEM header and footer. Reported by Coverity CID 89823. --- src/pem.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/pem.c b/src/pem.c index 9059477e..2e68c74d 100644 --- a/src/pem.c +++ b/src/pem.c @@ -67,6 +67,8 @@ _libssh2_pem_parse(LIBSSH2_SESSION * session, int ret; do { + *line = '\0'; + if (readline(line, LINE_SIZE, fp)) { return -1; } @@ -91,12 +93,18 @@ _libssh2_pem_parse(LIBSSH2_SESSION * session, b64datalen += linelen; } + *line = '\0'; + if (readline(line, LINE_SIZE, fp)) { ret = -1; goto out; } } while (strcmp(line, headerend) != 0); + if (!b64data) { + return -1; + } + if (libssh2_base64_decode(session, (char**) data, datalen, b64data, b64datalen)) { ret = -1;