ruby / ruby/openssl

servername_cb (and others) do odd things with lambda/proc?

Open
#195 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
276
Forks
200
Avg merge
1d 19h
Merged PRs (30d)
7

Description

Might be related to https://bugs.ruby-lang.org/issues/12705

When I do something like this:

server_context = OpenSSL::SSL::SSLContext.new.tap do |context|
	context.servername_cb = proc {|socket, name|
		if hosts.include? name
			OpenSSL::SSL::SSLContext.new.tap do |context|
				context.cert = certificates[name]
				context.key = keys[name]
			end
		end
	}
end

it works. But if I change proc to lambda, it fails with ArgumentError: wrong number of arguments (given 1, expected 2).

server_context = OpenSSL::SSL::SSLContext.new.tap do |context|
	context.servername_cb = lambda {|socket, name|
		if hosts.include? name
			OpenSSL::SSL::SSLContext.new.tap do |context|
				context.cert = certificates[name]
				context.key = keys[name]
			end
		end
	}
end

However, I feel like both should work. Does proc unwrap array implicitly?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the two callback forms through OpenSSL::SSL::SSLContext#servername_cb, comparing how the proc and lambda receive socket and name. Read the callback behavior around SSLContext.new and servername_cb, then confirm that the corrected behavior handles both forms with the expected arguments.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, ruby
Domain
security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.