diff --git a/src/sshagent/ASN1Key.cpp b/src/sshagent/ASN1Key.cpp index 3016e6d2a..2e6fa4222 100644 --- a/src/sshagent/ASN1Key.cpp +++ b/src/sshagent/ASN1Key.cpp @@ -86,7 +86,7 @@ namespace VALIDATE_RETURN(nextTag(stream, tag, len)); - if (tag != TAG_INT) { + if (tag != TAG_INT || len > 1024 * 1024 * 10) { return false; } diff --git a/tests/TestOpenSSHKey.cpp b/tests/TestOpenSSHKey.cpp index a20b248ed..45a2ee453 100644 --- a/tests/TestOpenSSHKey.cpp +++ b/tests/TestOpenSSHKey.cpp @@ -177,6 +177,18 @@ void TestOpenSSHKey::testParseRSA() QCOMPARE(key.fingerprint(QCryptographicHash::Md5), QString("MD5:c2:26:5b:3d:62:19:56:b0:c3:67:99:7a:a6:4c:66:06")); } +void TestOpenSSHKey::testParseRSABroken() +{ + const QString keyString = QString("-----BEGIN RSA PRIVATE KEY-----\n" + "MAACAQAChH////8=\n" + "-----END RSA PRIVATE KEY-----\n"); + + const QByteArray keyData = keyString.toLatin1(); + + OpenSSHKey key; + QVERIFY(!key.parsePKCS1PEM(keyData)); +} + void TestOpenSSHKey::testParseRSACompare() { const QString oldKeyString = QString("-----BEGIN RSA PRIVATE KEY-----\n" diff --git a/tests/TestOpenSSHKey.h b/tests/TestOpenSSHKey.h index b80ff919c..2a73afb1f 100644 --- a/tests/TestOpenSSHKey.h +++ b/tests/TestOpenSSHKey.h @@ -31,6 +31,7 @@ private slots: void testParse(); void testParseDSA(); void testParseRSA(); + void testParseRSABroken(); void testParseRSACompare(); void testParseECDSA256(); void testParseECDSA384();