Skip to content

Commit f653cfa

Browse files
committed
x509name: fix OpenSSL::X509::Name#{cmp,<=>}
Fix wrong use of X509_NAME_cmp() return value. OpenSSL::X509::Name#<=> could return 0 when the two objects aren't identical. Reported by Tyler Eckstein. CVE-2018-16395. Reference: https://hackerone.com/reports/387250
1 parent 1f90516 commit f653cfa

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

ext/openssl/ossl_x509name.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ ossl_x509name_cmp(VALUE self, VALUE other)
358358

359359
result = ossl_x509name_cmp0(self, other);
360360
if (result < 0) return INT2FIX(-1);
361-
if (result > 1) return INT2FIX(1);
361+
if (result > 0) return INT2FIX(1);
362362

363363
return INT2FIX(0);
364364
}

test/test_x509name.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,16 @@ def test_equals2
330330
end
331331

332332
def test_spaceship
333-
n1 = OpenSSL::X509::Name.parse 'CN=a'
334-
n2 = OpenSSL::X509::Name.parse 'CN=b'
335-
336-
assert_equal(-1, n1 <=> n2)
333+
n1 = OpenSSL::X509::Name.new([["CN", "a"]])
334+
n2 = OpenSSL::X509::Name.new([["CN", "a"]])
335+
n3 = OpenSSL::X509::Name.new([["CN", "ab"]])
336+
337+
assert_equal 0, n1 <=> n2
338+
assert_equal -1, n1 <=> n3
339+
assert_equal 0, n2 <=> n1
340+
assert_equal -1, n2 <=> n3
341+
assert_equal 1, n3 <=> n1
342+
assert_equal 1, n3 <=> n2
337343
end
338344

339345
def name_hash(name)

0 commit comments

Comments
 (0)