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);