summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2016-12-22 21:25:12 -0500
committerGitHub <noreply@github.com>2016-12-22 21:25:12 -0500
commitd0a6d43e16e4677d36bd0567978286938c1cfe6b (patch)
treea8376b9326f593fc3441520c36d25cebcb8f14f9
parent182f87eeacea3d6571100bf7e486177798a5c1d9 (diff)
parent3d9181d7bdd8e491f745dbc9e34bd20b6f6da069 (diff)
downloadcryptopp-git-d0a6d43e16e4677d36bd0567978286938c1cfe6b.tar.gz
Merge pull request #347 from tresorit/fix-asn1-decoder-dos
Fix possible DoS in ASN.1 decoders (CVE-2016-9939)
-rw-r--r--asn.cpp10
-rw-r--r--asn.h2
2 files changed, 12 insertions, 0 deletions
diff --git a/asn.cpp b/asn.cpp
index 297ff010..2e923ef7 100644
--- a/asn.cpp
+++ b/asn.cpp
@@ -123,6 +123,8 @@ size_t BERDecodeOctetString(BufferedTransformation &bt, SecByteBlock &str)
size_t bc;
if (!BERLengthDecode(bt, bc))
BERDecodeError();
+ if (bc > bt.MaxRetrievable())
+ BERDecodeError();
str.New(bc);
if (bc != bt.Get(str, bc))
@@ -139,6 +141,8 @@ size_t BERDecodeOctetString(BufferedTransformation &bt, BufferedTransformation &
size_t bc;
if (!BERLengthDecode(bt, bc))
BERDecodeError();
+ if (bc > bt.MaxRetrievable())
+ BERDecodeError();
bt.TransferTo(str, bc);
return bc;
@@ -161,6 +165,8 @@ size_t BERDecodeTextString(BufferedTransformation &bt, std::string &str, byte as
size_t bc;
if (!BERLengthDecode(bt, bc))
BERDecodeError();
+ if (bc > bt.MaxRetrievable())
+ BERDecodeError();
SecByteBlock temp(bc);
if (bc != bt.Get(temp, bc))
@@ -188,6 +194,10 @@ size_t BERDecodeBitString(BufferedTransformation &bt, SecByteBlock &str, unsigne
size_t bc;
if (!BERLengthDecode(bt, bc))
BERDecodeError();
+ if (bc == 0)
+ BERDecodeError();
+ if (bc > bt.MaxRetrievable())
+ BERDecodeError();
byte unused;
if (!bt.Get(unused))
diff --git a/asn.h b/asn.h
index ed9de52c..33f0dd09 100644
--- a/asn.h
+++ b/asn.h
@@ -498,6 +498,8 @@ void BERDecodeUnsigned(BufferedTransformation &in, T &w, byte asnTag = INTEGER,
bool definite = BERLengthDecode(in, bc);
if (!definite)
BERDecodeError();
+ if (bc > in.MaxRetrievable())
+ BERDecodeError();
SecByteBlock buf(bc);