EC_KEY_priv2buf (): check parameter sanity
authorJ Mohan Rao Arisankala <mohan@barracuda.com>
Wed, 24 Feb 2016 07:33:10 +0000 (13:03 +0530)
committerRich Salz <rsalz@openssl.org>
Fri, 26 Feb 2016 16:18:18 +0000 (11:18 -0500)
In EC_KEY_priv2buf(), check for pbuf sanity.
If invoked with NULL, gracefully returns the key length.

Signed-off-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
crypto/ec/ec_key.c

index c382e7e41e5f8d92478b55f07f58dbd835365661..439cfa27cc56663328619dee71d1a40202a5373c 100644 (file)
@@ -583,8 +583,8 @@ size_t EC_KEY_priv2buf(const EC_KEY *eckey, unsigned char **pbuf)
     size_t len;
     unsigned char *buf;
     len = EC_KEY_priv2oct(eckey, NULL, 0);
-    if (len == 0)
-        return 0;
+    if (len == 0 || pbuf == NULL)
+        return len;
     buf = OPENSSL_malloc(len);
     if (buf == NULL)
         return 0;