From 07716a6a8553cdf42cfdfa68df3c047c305bb6a2 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Fri, 5 Feb 2021 13:35:36 +0100 Subject: [PATCH] TT#108003 Do not print the DTLS certificate and private key on OOM When open_memstream() fails, we should not try to write to it. Change-Id: I9f92a1e1cc4aebe005039f28e5e3219e323e63c6 Warned-by: coverity --- daemon/dtls.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/daemon/dtls.c b/daemon/dtls.c index b080a9cc9..e0a8d2690 100644 --- a/daemon/dtls.c +++ b/daemon/dtls.c @@ -161,6 +161,10 @@ static void dump_cert(struct dtls_cert *cert) { /* cert */ fp = open_memstream(&buf, &len); + if (!fp) { + ilogs(crypto, LOG_ERROR, "Failed to allocate memory to dump DTLS certificate"); + return; + } PEM_write_X509(fp, cert->x509); fclose(fp); @@ -169,6 +173,10 @@ static void dump_cert(struct dtls_cert *cert) { /* key */ fp = open_memstream(&buf, &len); + if (!fp) { + ilogs(crypto, LOG_ERROR, "Failed to allocate memory to dump DTLS private key"); + return; + } PEM_write_PrivateKey(fp, cert->pkey, NULL, NULL, 0, 0, NULL); fclose(fp);