Skip to content

Commit ec99d71

Browse files
committed
do a bit more error checking
1 parent 9ed5dc5 commit ec99d71

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

main.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,18 @@ x509_cert_pub_key (napi_env env, napi_callback_info info)
100100
return NULL;
101101
}
102102

103+
if (public_key->n == NULL || public_key->e == NULL)
104+
{
105+
napi_throw_error (env, NULL, "One or more required values in the "
106+
"public key is null");
107+
RSA_free (public_key);
108+
EVP_PKEY_free (evp_pubkey);
109+
X509_free (x509);
110+
BIO_free (bio);
111+
free (buf);
112+
return NULL;
113+
}
114+
103115
n_hex = BN_bn2hex (public_key->n);
104116
e_hex = BN_bn2hex (public_key->e);
105117

@@ -189,6 +201,19 @@ rsa_priv_key (napi_env env, napi_callback_info info)
189201
return NULL;
190202
}
191203

204+
if (private_key->n == NULL || private_key->e == NULL ||
205+
private_key->d == NULL || private_key->p == NULL ||
206+
private_key->q == NULL || private_key->dmp1 == NULL ||
207+
private_key->dmq1 == NULL || private_key->iqmp == NULL)
208+
{
209+
napi_throw_error (env, NULL, "One or more required values in the "
210+
"private key is null");
211+
RSA_free (private_key);
212+
BIO_free (bio);
213+
free (buf);
214+
return NULL;
215+
}
216+
192217
n_hex = BN_bn2hex (private_key->n);
193218
e_hex = BN_bn2hex (private_key->e);
194219
d_hex = BN_bn2hex (private_key->d);

0 commit comments

Comments
 (0)