summaryrefslogtreecommitdiff
path: root/asn.cpp
diff options
context:
space:
mode:
authorGergely Nagy <ngg@tresorit.com>2016-12-14 13:19:01 +0100
committerGergely Nagy <ngg@tresorit.com>2016-12-14 13:19:01 +0100
commit3d9181d7bdd8e491f745dbc9e34bd20b6f6da069 (patch)
treebfbf787ff14d5396980742b5ea7105b7933333d7 /asn.cpp
parent20c58248075d9cbbe72b95372ac9d41a2c52cd8a (diff)
downloadcryptopp-git-3d9181d7bdd8e491f745dbc9e34bd20b6f6da069.tar.gz
Fix possible DoS in ASN.1 decoders (CVE-2016-9939)
Diffstat (limited to 'asn.cpp')
-rw-r--r--asn.cpp10
1 files changed, 10 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))