Skip to content

Commit 359f671

Browse files
ndosschematzbot
authored andcommitted
[ruby/openssl] x509name: check for error of X509_NAME_cmp()
These functions may return -2 to indicate an error according to the manual [1]. This can also be confirmed when looking at the code as it may call into i2d_X509_NAME() which can fail [2]. In such cases, the failure is reinterpreted as a "less than" comparison and the error is not reported, potentially leading to wrong results in userland code. [1] https://manpages.opensuse.org/Tumbleweed/openssl-3-doc/X509_NAME_cmp.33ssl.en.html [2] https://github.com/openssl/openssl/blob/f023662d1bde1fcb7fecf976b25a45afd55734b8/crypto/x509/x509_cmp.c#L269-L271 ruby/openssl@08e5547b85
1 parent cf25b0b commit 359f671

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

ext/openssl/ossl_x509name.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,17 @@ static int
366366
ossl_x509name_cmp0(VALUE self, VALUE other)
367367
{
368368
X509_NAME *name1, *name2;
369+
int result;
369370

370371
GetX509Name(self, name1);
371372
GetX509Name(other, name2);
372373

373-
return X509_NAME_cmp(name1, name2);
374+
result = X509_NAME_cmp(name1, name2);
375+
if (result == -2) {
376+
ossl_raise(eX509NameError, NULL);
377+
}
378+
379+
return result;
374380
}
375381

376382
/*

0 commit comments

Comments
 (0)