[PATCH] Perform bounds check when getting length from TLV

Greg Suarez <[email protected]>
Newsgroups gmane.comp.gnome.mono.devel
Message-ID <CAAkqo3uOHEyTQzPbOZzFvcAGpscEgWiDW6GnuomDwg46=LFEng@mail.gmail.com>
Some files with a malformed (malicious?) digital signature causes Decode()
in ASN1.cs to go into an infinite loop,
consuming more and more memory until the process is killed by the kernel
(tested on Linux).

---
 mcs/class/Mono.Security/Mono.Security/ASN1.cs | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/mcs/class/Mono.Security/Mono.Security/ASN1.cs
b/mcs/class/Mono.Security/Mono.Security/ASN1.cs
index 751a2ece4e6..d350f6fbf14 100644
--- a/mcs/class/Mono.Security/Mono.Security/ASN1.cs
+++ b/mcs/class/Mono.Security/Mono.Security/ASN1.cs
@@ -250,6 +250,11 @@ namespace Mono.Security {
  // sometimes we get trailing 0
  if (nTag == 0)
  continue;
+                if (anPos + nLength > anLength)
+                {
+                    anPos = anLength;
+                    break;
+                }

  ASN1 elm = Add (new ASN1 (nTag, aValue));

-- 
2.11.0

_______________________________________________
Mono-devel-list mailing list
[email protected]
http://lists.dot.net/mailman/listinfo/mono-devel-list
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.