Add ASN1_buf_print to print a buffer in ASN1_bn_print format.
[openssl.git] / crypto / asn1 / p8_pkey.c
index 90754831f2ab74da17c69303a8ea3d86b664eb39..59f1cd167a687712b7e11b8c0beb4cb09c4b247c 100644 (file)
@@ -1,4 +1,3 @@
-/* p8_pkey.c */
 /*
  * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
  * 1999.
@@ -58,7 +57,7 @@
  */
 
 #include <stdio.h>
-#include "cryptlib.h"
+#include "internal/cryptlib.h"
 #include <openssl/asn1t.h>
 #include <openssl/x509.h>
 
@@ -69,7 +68,8 @@ static int pkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
     /* Since the structure must still be valid use ASN1_OP_FREE_PRE */
     if (operation == ASN1_OP_FREE_PRE) {
         PKCS8_PRIV_KEY_INFO *key = (PKCS8_PRIV_KEY_INFO *)*pval;
-        if (key->pkey->value.octet_string)
+        if (key->pkey && key->pkey->type == V_ASN1_OCTET_STRING
+            && key->pkey->value.octet_string != NULL)
             OPENSSL_cleanse(key->pkey->value.octet_string->data,
                             key->pkey->value.octet_string->length);
     }
@@ -98,7 +98,7 @@ int PKCS8_pkey_set0(PKCS8_PRIV_KEY_INFO *priv, ASN1_OBJECT *aobj,
         int pmtype;
         ASN1_OCTET_STRING *oct;
         oct = ASN1_OCTET_STRING_new();
-        if (!oct)
+        if (oct == NULL)
             return 0;
         oct->data = penc;
         ppenc = &oct->data;