1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-07-26 14:41:04 +03:00

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.
This commit is contained in:
Marc Hoersken
2014-12-26 13:31:26 +01:00
parent 3835655f09
commit 8670f5da24

View File

@ -67,6 +67,8 @@ _libssh2_pem_parse(LIBSSH2_SESSION * session,
int ret; int ret;
do { do {
*line = '\0';
if (readline(line, LINE_SIZE, fp)) { if (readline(line, LINE_SIZE, fp)) {
return -1; return -1;
} }
@ -91,12 +93,18 @@ _libssh2_pem_parse(LIBSSH2_SESSION * session,
b64datalen += linelen; b64datalen += linelen;
} }
*line = '\0';
if (readline(line, LINE_SIZE, fp)) { if (readline(line, LINE_SIZE, fp)) {
ret = -1; ret = -1;
goto out; goto out;
} }
} while (strcmp(line, headerend) != 0); } while (strcmp(line, headerend) != 0);
if (!b64data) {
return -1;
}
if (libssh2_base64_decode(session, (char**) data, datalen, if (libssh2_base64_decode(session, (char**) data, datalen,
b64data, b64datalen)) { b64data, b64datalen)) {
ret = -1; ret = -1;