summary refs log tree commit diff
path: root/crypto/src/asn1/DerEnumerated.cs
diff options
context:
space:
mode:
authorDavid Hook <dgh@bouncycastle.org>2017-05-16 00:36:34 +1000
committerDavid Hook <dgh@bouncycastle.org>2017-05-16 00:36:34 +1000
commitfefed20bec7e07456cd50a710cc11fff18cf46c1 (patch)
tree4faca389cacee73d5e34d593ac1fd9795c9431de /crypto/src/asn1/DerEnumerated.cs
parentFix a bunch of RFC references in comments (diff)
downloadBouncyCastle.NET-ed25519-fefed20bec7e07456cd50a710cc11fff18cf46c1.tar.xz
Added validation of integer/enumerated encoding.
Diffstat (limited to 'crypto/src/asn1/DerEnumerated.cs')
-rw-r--r--crypto/src/asn1/DerEnumerated.cs13
1 files changed, 12 insertions, 1 deletions
diff --git a/crypto/src/asn1/DerEnumerated.cs b/crypto/src/asn1/DerEnumerated.cs
index 476b7fa9a..db27065bb 100644
--- a/crypto/src/asn1/DerEnumerated.cs
+++ b/crypto/src/asn1/DerEnumerated.cs
@@ -64,7 +64,18 @@ namespace Org.BouncyCastle.Asn1
         public DerEnumerated(
             byte[]   bytes)
         {
-            this.bytes = bytes;
+            if (bytes.Length > 1)
+            {
+                if (bytes[0] == 0 && (bytes[1] & 0x80) == 0)
+                {
+                    throw new ArgumentException("malformed enumerated");
+                }
+                if (bytes[0] == (byte)0xff && (bytes[1] & 0x80) != 0)
+                {
+                    throw new ArgumentException("malformed enumerated");
+                }
+            }
+            this.bytes = Arrays.Clone(bytes);
         }
 
         public BigInteger Value