diff options
author | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2014-05-16 19:00:04 +0200 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2014-05-16 19:00:04 +0200 |
commit | df4b741dfc41c1930fd73a5c7968479196961508 (patch) | |
tree | 1ea6d5de85f80c86cb2ea052d038d904fd46662d /lib/decoding.c | |
parent | 37a16434131c6ad8745b9accefec5cecb4cbb5b7 (diff) | |
download | libtasn1-df4b741dfc41c1930fd73a5c7968479196961508.tar.gz libtasn1-df4b741dfc41c1930fd73a5c7968479196961508.tar.bz2 libtasn1-df4b741dfc41c1930fd73a5c7968479196961508.zip |
simplified check for indefinite.
Diffstat (limited to 'lib/decoding.c')
-rw-r--r-- | lib/decoding.c | 51 |
1 files changed, 24 insertions, 27 deletions
diff --git a/lib/decoding.c b/lib/decoding.c index 0244f37..3de6d6d 100644 --- a/lib/decoding.c +++ b/lib/decoding.c @@ -41,6 +41,8 @@ # define warn() #endif +#define HAVE_TWO(x) (x>=2?1:0) + #define DECR_LEN(l, s) do { \ l -= s; \ if (l < 0) { \ @@ -901,16 +903,14 @@ asn1_der_decoding (asn1_node * element, const void *ider, int ider_len, len2 = _asn1_strtol (p2->value, NULL, 10); if (len2 == -1) { - DECR_LEN(ider_len, 2); - if (!der[counter] && !der[counter + 1]) + if (HAVE_TWO(ider_len) && !der[counter] && !der[counter + 1]) { p = p2; move = UP; counter += 2; + DECR_LEN(ider_len, 2); continue; } - else - ider_len += 2; } else if (counter == len2) { @@ -1255,10 +1255,8 @@ asn1_der_decoding (asn1_node * element, const void *ider, int ider_len, len2 = _asn1_strtol (p->value, NULL, 10); if (len2 == -1) { /* indefinite length method */ - DECR_LEN(ider_len, 2); - if ((der[counter]) || der[counter + 1]) + if (!HAVE_TWO(ider_len) || ((der[counter]) || der[counter + 1])) { - ider_len += 2; _asn1_append_sequence_set (p); p = p->down; while (p->right) @@ -1268,6 +1266,7 @@ asn1_der_decoding (asn1_node * element, const void *ider, int ider_len, } _asn1_set_value (p, NULL, 0); + DECR_LEN(ider_len, 2); counter += 2; } else @@ -1559,16 +1558,14 @@ asn1_der_decoding_startEnd (asn1_node element, const void *ider, int ider_len, len2 = _asn1_strtol (p2->value, NULL, 10); if (len2 == -1) { - DECR_LEN(ider_len, 2); - if (!der[counter] && !der[counter + 1]) + if (HAVE_TWO(ider_len) && !der[counter] && !der[counter + 1]) { p = p2; move = UP; counter += 2; + DECR_LEN(ider_len, 2); continue; } - else - ider_len += 2; } else if (counter == len2) { @@ -1740,11 +1737,11 @@ asn1_der_decoding_startEnd (asn1_node element, const void *ider, int ider_len, } else { - DECR_LEN(ider_len, 2); - if (!der[counter] && !der[counter + 1]) /* indefinite length method */ - counter += 2; - else - ider_len += 2; + if (HAVE_TWO(ider_len) && !der[counter] && !der[counter + 1]) /* indefinite length method */ + { + counter += 2; + DECR_LEN(ider_len, 2); + } move = RIGHT; } break; @@ -1765,11 +1762,11 @@ asn1_der_decoding_startEnd (asn1_node element, const void *ider, int ider_len, if (len3 == -1) { - DECR_LEN(ider_len, 2); - if (!der[counter] && !der[counter + 1]) - counter += 2; - else - ider_len += 2; + if (HAVE_TWO(ider_len) && !der[counter] && !der[counter + 1]) + { + DECR_LEN(ider_len, 2); + counter += 2; + } } if (len3) @@ -1783,11 +1780,11 @@ asn1_der_decoding_startEnd (asn1_node element, const void *ider, int ider_len, } else { - DECR_LEN(ider_len, 2); - if (!der[counter] && !der[counter + 1]) /* indefinite length method */ - counter += 2; - else - ider_len += 2; + if (HAVE_TWO(ider_len) && !der[counter] && !der[counter + 1]) /* indefinite length method */ + { + DECR_LEN(ider_len, 2); + counter += 2; + } } move = RIGHT; break; @@ -1799,7 +1796,7 @@ asn1_der_decoding_startEnd (asn1_node element, const void *ider, int ider_len, warn(); return ASN1_DER_ERROR; } - + DECR_LEN(ider_len, len2); len4 = |