Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for ASN1::Constructive 'each' implementation #96

Merged
merged 1 commit into from
Dec 29, 2016
Merged

Fix for ASN1::Constructive 'each' implementation #96

merged 1 commit into from
Dec 29, 2016

Conversation

CBonnell
Copy link

This change fixes the ASN1::Constructive.each implementation that was broken with commit 36bf7f4 (see @tidoublemy's comment on that commit for code to reproduce the issue).

Included are two small tests to test for correct behavior of the each implementation and that an appropriate exception will be raised (instead of SIGSEGV'ing) when non-array data is specified in Ruby for the value attribute.

Copy link
Member

@rhenium rhenium left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CBonnell @tidoublemy Oops, that commit was completely broken. Thank you for reporting and fixing!

@@ -566,6 +566,19 @@ def test_decode_constructed_overread
assert_equal 17, ret[0][6]
end

def test_constructive_each
data = ['test','data']
seq = OpenSSL::ASN1::Sequence.new data
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'data' should be an array of OpenSSL::ASN1::ASN1Data instances rather than of String.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, stupid mistake on my part. Should be fixed now.

def test_constructive_nonarray_each
seq = OpenSSL::ASN1::Sequence.new 5

assert_raise(NoMethodError) { seq.each }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for being careful, but I think raising NoMethodError is an implementation detail and is not part of the spec that should be tested.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the NoMethodError exception type specification from assert_raise.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It really hassles but we can't use assert_raise without specifying the exact exception type, because this file is shared with the ruby tree (https://github.com/ruby/ruby/blob/trunk/test/openssl/test_asn1.rb) where the test framework behaves differently. I think not testing is fine this time.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing that out. I was unaware of the code sharing with the Ruby tree. I removed this test in the latest commit.

@rhenium
Copy link
Member

rhenium commented Dec 29, 2016

@CBonnell Could you change target branch to 'maint'? This needs to be included in the next 2.0 release.

@CBonnell CBonnell changed the base branch from master to maint December 29, 2016 15:54
@rhenium
Copy link
Member

rhenium commented Dec 29, 2016

@CBonnell Thank you! It looks like changing target branch rolled up irrelevant changes from master. Could you rebase on top of 'maint', and squash the three commits?

@rhenium rhenium merged commit 46674c3 into ruby:maint Dec 29, 2016
@rhenium
Copy link
Member

rhenium commented Dec 29, 2016

Merged, thanks!

rhenium referenced this pull request Dec 29, 2016
Don't blindy assume that the value which can be modified from Ruby code
is always an Array, and just call its #each method.
@CBonnell
Copy link
Author

@rhenium, thanks for reviewing and merging this PR so quickly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants