Backport #7980

Segmentation fault when generating new key with OpenSSL

Added by Dimitri Peka about 1 year ago. Updated about 1 year ago.

[ruby-core:53007]
Status:Closed
Priority:Normal
Assignee:Usaku NAKAMURA

Description

=begin
The code below makes ruby to crash

If I change
cert.version, cert.serial = 2
to
cert.version = 2
cert.serial = 2
it passes to the undefined variable ((|root_ca|)) as expected

#!/usr/bin/ruby
# encoding: utf-8

require 'openssl'

def newkey
key = OpenSSL::PKey::RSA.new 4096
cert = OpenSSL::X509::Certificate.new
cert.version, cert.serial = 2
cert.subject = OpenSSL::X509::Name.parse '/DC=Ivan Ivanov/DC=8055645654/DC=h@h/DC=/OU=client/O=Kontora/C=KZ'
cert.issuer = root
ca.subject
cert.publickey = key.publickey
cert.notbefore = Time.now
cert.not
after = cert.notbefore + 2 * 365 * 24 * 60 * 60
ef = OpenSSL::X509::ExtensionFactory.new
ef.subject
certificate = cert
ef.issuercertificate = rootca
cert.addextension(ef.createextension("keyUsage","digitalSignature", true))
cert.addextension(ef.createextension("subjectKeyIdentifier","hash",false))
cert.sign(@@root_key, OpenSSL::Digest::SHA256.new)
return cert
end

puts new_key

=end

dump (11.2 KB) Dimitri Peka, 02/28/2013 04:27 AM

Associated revisions

Revision 39980
Added by Usaku NAKAMURA about 1 year ago

merge revision(s) 35159: [Backport #7980]

* ext/openssl/ossl_asn1.c: raise TypeError when trying to encode nil
  values for Primitive instances. 

* test/openssl/test_asn1.rb: Assert consistent behavior when
  encoding nil values: Primitives raise TypeError, Constructives
  raise NoMethodError.
  Fixes [Bug #6102]

History

#1 Updated by Nobuyoshi Nakada about 1 year ago

  • Description updated (diff)
  • Category set to ext
  • Status changed from Open to Assigned
  • Assignee set to Martin Bosslet

#2 Updated by Nobuyoshi Nakada about 1 year ago

  • Tracker changed from Bug to Backport
  • Project changed from ruby-trunk to Backport93
  • Category deleted (ext)

#3 Updated by Nobuyoshi Nakada about 1 year ago

  • Assignee changed from Martin Bosslet to Usaku NAKAMURA

Seems r35159.

#4 Updated by Usaku NAKAMURA about 1 year ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r39980.
Dimitri, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


merge revision(s) 35159: [Backport #7980]

* ext/openssl/ossl_asn1.c: raise TypeError when trying to encode nil
  values for Primitive instances. 

* test/openssl/test_asn1.rb: Assert consistent behavior when
  encoding nil values: Primitives raise TypeError, Constructives
  raise NoMethodError.
  Fixes [Bug #6102]

Also available in: Atom PDF