From 935fa407e3c09532f79e12eccb30fa36595b1316 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Mon, 2 Mar 2020 10:03:02 -0600 Subject: [PATCH 1/3] ASN1: add unit test for malformed ASN1 strings --- tests/Unit/File/X509/X509Test.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/Unit/File/X509/X509Test.php b/tests/Unit/File/X509/X509Test.php index 2f95df2c..e4ccdd59 100644 --- a/tests/Unit/File/X509/X509Test.php +++ b/tests/Unit/File/X509/X509Test.php @@ -733,4 +733,18 @@ ut3+b2Xvzq8yzmHMFtLIJ6Afu1jJpqD82BUAFcvi5vhnP8M7b974R18WCOpgNQvXDI+2/8ZINeU= $r = $x509->loadX509($r); $this->assertSame($r['tbsCertificate']['extensions'][5]['extnValue']['excludedSubtrees'][1]['base']['iPAddress'], array('0.0.0.0', '0.0.0.0')); } + + /** + * @group github1456 + */ + public function testRandomString() + { + $a = 'da7e705569d4196cd49cf3b3d92cd435ca34ccbe'; + $a = pack('H*', $a); + + $x509 = new File_X509(); + $r = $x509->loadX509($a); + + $this->assertFalse($r); + } } From fc0832ae99b13ce34ceb45f1125927a5d632288c Mon Sep 17 00:00:00 2001 From: terrafrost Date: Mon, 2 Mar 2020 10:18:30 -0600 Subject: [PATCH 2/3] ASN1: fix for malformed ASN1 strings --- phpseclib/File/ASN1.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/phpseclib/File/ASN1.php b/phpseclib/File/ASN1.php index 4bd355a1..98fe4b83 100644 --- a/phpseclib/File/ASN1.php +++ b/phpseclib/File/ASN1.php @@ -577,6 +577,10 @@ class File_ASN1 */ function asn1map($decoded, $mapping, $special = array()) { + if (!is_array($decoded)) { + return false; + } + if (isset($mapping['explicit']) && is_array($decoded['content'])) { $decoded = $decoded['content'][0]; } From 0cdae704b6f6ab81d4da13c47698529be1ad5041 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Mon, 2 Mar 2020 10:34:52 -0600 Subject: [PATCH 3/3] Tests/X509: update unit test for 2.0 --- tests/Unit/File/X509/X509Test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/File/X509/X509Test.php b/tests/Unit/File/X509/X509Test.php index 92d756f2..0d019ede 100644 --- a/tests/Unit/File/X509/X509Test.php +++ b/tests/Unit/File/X509/X509Test.php @@ -806,7 +806,7 @@ ut3+b2Xvzq8yzmHMFtLIJ6Afu1jJpqD82BUAFcvi5vhnP8M7b974R18WCOpgNQvXDI+2/8ZINeU= $a = 'da7e705569d4196cd49cf3b3d92cd435ca34ccbe'; $a = pack('H*', $a); - $x509 = new File_X509(); + $x509 = new X509(); $r = $x509->loadX509($a); $this->assertFalse($r);