diff options
author | Dariusz Michaluk <d.michaluk@samsung.com> | 2018-06-15 11:14:03 +0200 |
---|---|---|
committer | Dariusz Michaluk <d.michaluk@samsung.com> | 2018-06-15 11:14:03 +0200 |
commit | e527f54afdf27ab8ce73a22d05d69e5482f5e92b (patch) | |
tree | aac02c45c01b4330297e82c082bd6209b8d8b6bc /lib/decoding.c | |
parent | c38ae6ad7adfdfe3cb40ff348277ca32a16756b0 (diff) | |
download | libtasn1-e527f54afdf27ab8ce73a22d05d69e5482f5e92b.tar.gz libtasn1-e527f54afdf27ab8ce73a22d05d69e5482f5e92b.tar.bz2 libtasn1-e527f54afdf27ab8ce73a22d05d69e5482f5e92b.zip |
Imported Upstream version 4.13upstream/4.13
Diffstat (limited to 'lib/decoding.c')
-rw-r--r-- | lib/decoding.c | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/lib/decoding.c b/lib/decoding.c index 2240b09..05dc236 100644 --- a/lib/decoding.c +++ b/lib/decoding.c @@ -43,8 +43,22 @@ #define HAVE_TWO(x) (x>=2?1:0) +/* Decoding flags (dflags) used in several decoding functions. + * DECODE_FLAG_HAVE_TAG: The provided buffer includes a tag + * DECODE_FLAG_INDEFINITE: The provided buffer is of indefinite encoding (useful + * when no tags are present). + * DECODE_FLAG_LEVEL1: Internal flag to indicate a level of recursion for BER strings. + * DECODE_FLAG_LEVEL2: Internal flag to indicate two levels of recursion for BER strings. + * DECODE_FLAG_LEVEL3: Internal flag to indicate three levels of recursion for BER strings. + * This is the maximum levels of recursion possible to prevent stack + * exhaustion. + */ + #define DECODE_FLAG_HAVE_TAG 1 #define DECODE_FLAG_INDEFINITE (1<<1) +#define DECODE_FLAG_LEVEL1 (1<<2) +#define DECODE_FLAG_LEVEL2 (1<<3) +#define DECODE_FLAG_LEVEL3 (1<<4) #define DECR_LEN(l, s) do { \ l -= s; \ @@ -2216,7 +2230,8 @@ _asn1_decode_simple_ber (unsigned int etype, const unsigned char *der, } /* indefinite constructed */ - if (((dflags & DECODE_FLAG_INDEFINITE) || class == ASN1_CLASS_STRUCTURED) && ETYPE_IS_STRING(etype)) + if ((((dflags & DECODE_FLAG_INDEFINITE) || class == ASN1_CLASS_STRUCTURED) && ETYPE_IS_STRING(etype)) && + !(dflags & DECODE_FLAG_LEVEL3)) { len_len = 1; @@ -2236,8 +2251,17 @@ _asn1_decode_simple_ber (unsigned int etype, const unsigned char *der, do { unsigned tmp_len; + unsigned flags = DECODE_FLAG_HAVE_TAG; + + if (dflags & DECODE_FLAG_LEVEL1) + flags |= DECODE_FLAG_LEVEL2; + else if (dflags & DECODE_FLAG_LEVEL2) + flags |= DECODE_FLAG_LEVEL3; + else + flags |= DECODE_FLAG_LEVEL1; - result = asn1_decode_simple_ber(etype, p, der_len, &out, &out_len, &tmp_len); + result = _asn1_decode_simple_ber(etype, p, der_len, &out, &out_len, &tmp_len, + flags); if (result != ASN1_SUCCESS) { warn(); |