Merge pull request #23670 from apolcyn/fix_segv

Fix ruby segfault on nil optional creds params
pull/23679/head
apolcyn 4 years ago committed by GitHub
commit 4e7ec48b0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  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