Call ordering functions with the right length
authorKurt Roeckx <kurt@roeckx.be>
Sun, 20 Apr 2014 14:50:00 +0000 (16:50 +0200)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Sat, 26 Apr 2014 07:57:42 +0000 (09:57 +0200)
We're going to insert the length of the set and at this point are going to order
it.  But we called it with the wrong length.  Also updates the check to only do
it when the buffer isn't to small.

lib/coding.c

index e640c0b..052c947 100644 (file)
@@ -1167,7 +1167,7 @@ asn1_der_coding (asn1_node element, const char *name, void *ider, int *len,
              len2 = _asn1_strtol (p->value, NULL, 10);
              _asn1_set_value (p, NULL, 0);
              if ((type_field (p->type) == ASN1_ETYPE_SET) && (max_len >= 0))
-               _asn1_ordering_set (der + len2, max_len - len2, p);
+               _asn1_ordering_set (der + len2, counter - len2, p);
              asn1_length_der (counter - len2, temp, &len3);
              max_len -= len3;
              if (max_len >= 0)
@@ -1207,7 +1207,7 @@ asn1_der_coding (asn1_node element, const char *name, void *ider, int *len,
              len2 = _asn1_strtol (p->value, NULL, 10);
              _asn1_set_value (p, NULL, 0);
              if ((type_field (p->type) == ASN1_ETYPE_SET_OF)
-                 && (max_len - len2 > 0))
+                 && (counter - len2 > 0) && (max_len >= 0))
                {
                  _asn1_ordering_set_of (der + len2, max_len - len2, p);
                }