diff --git a/src/node_crypto.cc b/src/node_crypto.cc index c7b8c218b88af3..ce1be1e83ac092 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -4835,10 +4835,11 @@ void GetSSLCiphers(const FunctionCallbackInfo& args) { SSLPointer ssl(SSL_new(ctx.get())); CHECK(ssl); - Local arr = Array::New(env->isolate()); STACK_OF(SSL_CIPHER)* ciphers = SSL_get_ciphers(ssl.get()); + int n = sk_SSL_CIPHER_num(ciphers); + Local arr = Array::New(env->isolate(), n); - for (int i = 0; i < sk_SSL_CIPHER_num(ciphers); ++i) { + for (int i = 0; i < n; ++i) { const SSL_CIPHER* cipher = sk_SSL_CIPHER_value(ciphers, i); arr->Set(env->context(), i,