|
|
fe27b6 |
From 3ab0720cc4a6b2525850ea192a99235873f22d6b Mon Sep 17 00:00:00 2001
|
|
|
fe27b6 |
From: Kazuki Yamaguchi <k@rhe.jp>
|
|
|
fe27b6 |
Date: Fri, 27 Jul 2018 17:01:04 +0900
|
|
|
fe27b6 |
Subject: [PATCH] x509name: fix OpenSSL::X509::Name#{cmp,<=>}
|
|
|
fe27b6 |
|
|
|
fe27b6 |
Fix wrong use of X509_NAME_cmp() return value. OpenSSL::X509::Name#<=>
|
|
|
fe27b6 |
could return 0 when the two objects aren't identical.
|
|
|
fe27b6 |
|
|
|
fe27b6 |
Reported by Tyler Eckstein. CVE-2018-16395.
|
|
|
fe27b6 |
|
|
|
fe27b6 |
Reference: https://hackerone.com/reports/387250
|
|
|
fe27b6 |
---
|
|
|
fe27b6 |
ext/openssl/ossl_x509name.c | 2 +-
|
|
|
fe27b6 |
test/openssl/test_x509name.rb | 14 ++++++++++----
|
|
|
fe27b6 |
2 files changed, 11 insertions(+), 5 deletions(-)
|
|
|
fe27b6 |
|
|
|
fe27b6 |
diff --git a/ext/openssl/ossl_x509name.c b/ext/openssl/ossl_x509name.c
|
|
|
fe27b6 |
index 4b397055ab..a2662159e3 100644
|
|
|
fe27b6 |
--- a/ext/openssl/ossl_x509name.c
|
|
|
fe27b6 |
+++ b/ext/openssl/ossl_x509name.c
|
|
|
fe27b6 |
@@ -321,7 +321,7 @@ ossl_x509name_cmp(VALUE self, VALUE other)
|
|
|
fe27b6 |
|
|
|
fe27b6 |
result = ossl_x509name_cmp0(self, other);
|
|
|
fe27b6 |
if (result < 0) return INT2FIX(-1);
|
|
|
fe27b6 |
- if (result > 1) return INT2FIX(1);
|
|
|
fe27b6 |
+ if (result > 0) return INT2FIX(1);
|
|
|
fe27b6 |
|
|
|
fe27b6 |
return INT2FIX(0);
|
|
|
fe27b6 |
}
|
|
|
fe27b6 |
diff --git a/test/openssl/test_x509name.rb b/test/openssl/test_x509name.rb
|
|
|
fe27b6 |
index de35fc303a..642d7094a8 100644
|
|
|
fe27b6 |
--- a/test/openssl/test_x509name.rb
|
|
|
fe27b6 |
+++ b/test/openssl/test_x509name.rb
|
|
|
fe27b6 |
@@ -337,10 +337,16 @@ class OpenSSL::TestX509Name < Test::Unit::TestCase
|
|
|
fe27b6 |
end
|
|
|
fe27b6 |
|
|
|
fe27b6 |
def test_spaceship
|
|
|
fe27b6 |
- n1 = OpenSSL::X509::Name.parse 'CN=a'
|
|
|
fe27b6 |
- n2 = OpenSSL::X509::Name.parse 'CN=b'
|
|
|
fe27b6 |
-
|
|
|
fe27b6 |
- assert_equal(-1, n1 <=> n2)
|
|
|
fe27b6 |
+ n1 = OpenSSL::X509::Name.new([["CN", "a"]])
|
|
|
fe27b6 |
+ n2 = OpenSSL::X509::Name.new([["CN", "a"]])
|
|
|
fe27b6 |
+ n3 = OpenSSL::X509::Name.new([["CN", "ab"]])
|
|
|
fe27b6 |
+
|
|
|
fe27b6 |
+ assert_equal 0, n1 <=> n2
|
|
|
fe27b6 |
+ assert_equal -1, n1 <=> n3
|
|
|
fe27b6 |
+ assert_equal 0, n2 <=> n1
|
|
|
fe27b6 |
+ assert_equal -1, n2 <=> n3
|
|
|
fe27b6 |
+ assert_equal 1, n3 <=> n1
|
|
|
fe27b6 |
+ assert_equal 1, n3 <=> n2
|
|
|
fe27b6 |
end
|
|
|
fe27b6 |
|
|
|
fe27b6 |
def name_hash(name)
|
|
|
fe27b6 |
--
|
|
|
fe27b6 |
2.17.1
|
|
|
fe27b6 |
|