From 1e87eae3b769b7ae6789f9bc5d2d530a9a411dd7 Mon Sep 17 00:00:00 2001 From: Takashi Kojo Date: Wed, 4 Jul 2018 07:51:46 +0900 Subject: [PATCH] i2d_RSAPublicKey(rsa, NULL) --- src/ssl.c | 4 ++-- tests/api.c | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ssl.c b/src/ssl.c index 6c5841b51..fc0c03189 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -28482,8 +28482,8 @@ int wolfSSL_i2d_RSAPublicKey(WOLFSSL_RSA *rsa, const unsigned char **pp) XFREE(der, NULL, DYNAMIC_TYPE_TMP_BUFFER); return ret; } - - *pp = der; + if((pp != NULL) && (ret >= 0)) + *pp = der; return ret; } #endif /* #if !defined(HAVE_FAST_RSA) */ diff --git a/tests/api.c b/tests/api.c index 88e3f8338..e6e8e6552 100644 --- a/tests/api.c +++ b/tests/api.c @@ -19180,6 +19180,7 @@ static void test_wolfSSL_RSA_DER(void) { AssertNotNull(d2i_RSAPublicKey(&rsa, &pub[i].der, pub[i].sz)); AssertNotNull(rsa); + AssertIntEQ(i2d_RSAPublicKey(rsa, NULL), pub[i].sz); buff = NULL; AssertIntEQ(i2d_RSAPublicKey(rsa, &buff), pub[i].sz); AssertNotNull(buff);