1 From 3d9181d7bdd8e491f745dbc9e34bd20b6f6da069 Mon Sep 17 00:00:00 2001
2 From: Gergely Nagy <ngg@tresorit.com>
3 Date: Wed, 14 Dec 2016 13:19:01 +0100
4 Subject: [PATCH] Fix possible DoS in ASN.1 decoders (CVE-2016-9939)
6 Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
8 asn.cpp | 10 ++++++++++
10 2 files changed, 12 insertions(+)
12 diff --git a/asn.cpp b/asn.cpp
13 index 297ff01..2e923ef 100644
16 @@ -123,6 +123,8 @@ size_t BERDecodeOctetString(BufferedTransformation &bt, SecByteBlock &str)
18 if (!BERLengthDecode(bt, bc))
20 + if (bc > bt.MaxRetrievable())
24 if (bc != bt.Get(str, bc))
25 @@ -139,6 +141,8 @@ size_t BERDecodeOctetString(BufferedTransformation &bt, BufferedTransformation &
27 if (!BERLengthDecode(bt, bc))
29 + if (bc > bt.MaxRetrievable())
32 bt.TransferTo(str, bc);
34 @@ -161,6 +165,8 @@ size_t BERDecodeTextString(BufferedTransformation &bt, std::string &str, byte as
36 if (!BERLengthDecode(bt, bc))
38 + if (bc > bt.MaxRetrievable())
41 SecByteBlock temp(bc);
42 if (bc != bt.Get(temp, bc))
43 @@ -188,6 +194,10 @@ size_t BERDecodeBitString(BufferedTransformation &bt, SecByteBlock &str, unsigne
45 if (!BERLengthDecode(bt, bc))
49 + if (bc > bt.MaxRetrievable())
54 diff --git a/asn.h b/asn.h
55 index ed9de52..33f0dd0 100644
58 @@ -498,6 +498,8 @@ void BERDecodeUnsigned(BufferedTransformation &in, T &w, byte asnTag = INTEGER,
59 bool definite = BERLengthDecode(in, bc);
62 + if (bc > in.MaxRetrievable())