Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ext/openssl/ossl_asn1.c
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,8 @@ int_ossl_asn1_decode0_cons(unsigned char **pp, long max_len, long length,
return asn1data;
}

#define MAX_NESTING_DEPTH 200

static VALUE
ossl_asn1_decode0(unsigned char **pp, long length, long *offset, int depth,
int yield, long *num_read)
Expand All @@ -905,6 +907,10 @@ ossl_asn1_decode0(unsigned char **pp, long length, long *offset, int depth,
int tag, tc, j;
VALUE asn1data, tag_class;

if (depth > MAX_NESTING_DEPTH) {
ossl_raise(eASN1Error, "nesting depth %d exceeds limit", depth);
}

p = *pp;
start = p;
p0 = p;
Expand Down
14 changes: 11 additions & 3 deletions proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3211,10 +3211,18 @@ rb_method_entry_location(const rb_method_entry_t *me)

/*
* call-seq:
* meth.source_location -> [String, Integer]
* source_location -> location
*
* Returns the Ruby source filename and line number containing this method
* or nil if this method was not defined in Ruby (i.e. native).
* Returns a two-element array containing the Ruby source filename
* as a string and the line number integer where +self+ is defined:
*
* def greeting = "hello"
* method(:greeting).source_location # => ["test.rb", 1]
*
* Returns nil if +self+ is not a method defined in Ruby (i.e. defined
* using native code):
*
* Kernel.method(:puts).source_location # => nil
*/

VALUE
Expand Down
14 changes: 14 additions & 0 deletions test/openssl/test_asn1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,20 @@ def test_decode_constructed_overread
assert_equal 17, ret[0][6]
end

def test_decode_constructed_deeply_nested
bool = OpenSSL::ASN1::Boolean.new(true)
nested_100 = B(%w{ 30 80 }) * 100 + bool.to_der + B(%w{ 00 00 }) * 100
decoded = OpenSSL::ASN1.decode(nested_100)
assert_equal(nested_100, decoded.to_der)
content = 100.times.inject(decoded) { |a,| a.value[0] }
assert_kind_of(OpenSSL::ASN1::Boolean, content)

nested_500 = B(%w{ 30 80 }) * 500 + bool.to_der + B(%w{ 00 00 }) * 500
assert_raise_with_message(OpenSSL::ASN1::ASN1Error, /nesting depth/) {
OpenSSL::ASN1.decode(nested_500)
}
end

def test_constructive_each
data = [OpenSSL::ASN1::Integer.new(0), OpenSSL::ASN1::Integer.new(1)]
seq = OpenSSL::ASN1::Sequence.new data
Expand Down
36 changes: 2 additions & 34 deletions test/openssl/test_ts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,11 @@

class OpenSSL::TestTimestamp < OpenSSL::TestCase
def intermediate_key
@intermediate_key ||= OpenSSL::PKey::RSA.new <<-_end_of_pem_
-----BEGIN RSA PRIVATE KEY-----
MIICWwIBAAKBgQCcyODxH+oTrr7l7MITWcGaYnnBma6vidCCJjuSzZpaRmXZHAyH
0YcY4ttC0BdJ4uV+cE05IySVC7tyvVfFb8gFQ6XJV+AEktP+XkLbcxZgj9d2NVu1
ziXdI+ldXkPnMhyWpMS5E7SD6gflv9NhUYEsmAGsUgdK6LDmm2W2/4TlewIDAQAB
AoGAYgx6KDFWONLqjW3f/Sv/mGYHUNykUyDzpcD1Npyf797gqMMSzwlo3FZa2tC6
D7n23XirwpTItvEsW9gvgMikJDPlThAeGLZ+L0UbVNNBHVxGP998Nda1kxqKvhRE
pfZCKc7PLM9ZXc6jBTmgxdcAYfVCCVUoa2mEf9Ktr3BlI4kCQQDQAM09+wHDXGKP
o2UnCwCazGtyGU2r0QCzHlh9BVY+KD2KjjhuWh86rEbdWN7hEW23Je1vXIhuM6Pa
/Ccd+XYnAkEAwPZ91PK6idEONeGQ4I3dyMKV2SbaUjfq3MDL4iIQPQPuj7QsBO/5
3Nf9ReSUUTRFCUVwoC8k4Z1KAJhR/K/ejQJANE7PTnPuGJQGETs09+GTcFpR9uqY
FspDk8fg1ufdrVnvSAXF+TJewiGK3KU5v33jinhWQngRsyz3Wt2odKhEZwJACbjh
oicQqvzz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RH9NKey
GaL27FRs4fRWf9OmxPhUVgIyGzLGXrueemvQUDHObA==
-----END RSA PRIVATE KEY-----
_end_of_pem_
@ee_key ||= Fixtures.pkey("rsa-2")
end

def ca_cert
Expand Down