From f9a7d8dde7b260d19a042729d20dd1c6d68a6276 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Thu, 20 Feb 2020 01:08:52 +0700 Subject: Stricter header validation for PEM files --- crypto/src/util/io/pem/PemReader.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'crypto/src/util') diff --git a/crypto/src/util/io/pem/PemReader.cs b/crypto/src/util/io/pem/PemReader.cs index bf712b6de..61e132fa7 100644 --- a/crypto/src/util/io/pem/PemReader.cs +++ b/crypto/src/util/io/pem/PemReader.cs @@ -39,11 +39,14 @@ namespace Org.BouncyCastle.Utilities.IO.Pem { line = line.Substring(BeginString.Length); int index = line.IndexOf('-'); - string type = line.Substring(0, index); - if (index > 0) - return LoadObject(type); - } + if (index > 0 && Platform.EndsWith(line, "-----") && (line.Length - index) == 5) + { + string type = line.Substring(0, index); + + return LoadObject(type); + } + } return null; } -- cgit 1.4.1