Fix ruby segfault on nil optional creds params

pull/23670/head
Alexander Polcyn 4 years ago
parent 94c44af070
commit a12cf6996b
  1. 9
      src/ruby/ext/grpc/rb_channel_credentials.c
  2. 10
      src/ruby/spec/channel_credentials_spec.rb

@ -165,6 +165,15 @@ static VALUE grpc_rb_channel_credentials_init(int argc, VALUE* argv,
if (pem_private_key == Qnil && pem_cert_chain == Qnil) {
creds = grpc_ssl_credentials_create(pem_root_certs_cstr, NULL, NULL, NULL);
} else {
if (pem_private_key == Qnil) {
rb_raise(
rb_eRuntimeError,
"could not create a credentials because pem_private_key is NULL");
}
if (pem_cert_chain == Qnil) {
rb_raise(rb_eRuntimeError,
"could not create a credentials because pem_cert_chain is NULL");
}
key_cert_pair.private_key = RSTRING_PTR(pem_private_key);
key_cert_pair.cert_chain = RSTRING_PTR(pem_cert_chain);
creds = grpc_ssl_credentials_create(pem_root_certs_cstr, &key_cert_pair,

@ -50,6 +50,16 @@ describe GRPC::Core::ChannelCredentials do
blk = proc { ChannelCredentials.new(nil) }
expect(&blk).not_to raise_error
end
it 'fails gracefully with constructed with a nil private key' do
blk = proc { GRPC::Core::ChannelCredentials.new(nil, nil, '') }
expect(&blk).to raise_error
end
it 'fails gracefully with constructed with a nil cert chain' do
blk = proc { GRPC::Core::ChannelCredentials.new(nil, '', nil) }
expect(&blk).to raise_error
end
end
describe '#compose' do

Loading…
Cancel
Save