Browse Source

Add Testcase that UTF-8 decoding respects the ASN.1 length

Signed-off-by: Steffen Jaeckel <[email protected]>
Steffen Jaeckel 2 years ago
parent
commit
c939720699
1 changed files with 8 additions and 1 deletions
  1. 8 1
      tests/der_test.c

+ 8 - 1
tests/der_test.c

@@ -1400,7 +1400,9 @@ static void s_der_regression_test(void)
                                             "\xaa"               /* One byte padding */
                                             "\x04\x82\xff\xff";  /* Start OCTET sequence of length 0xffff */
                                                                  /* (this will include the adjacent data into the decoded certificate) */
-   unsigned long len;
+   static const unsigned char utf8_length[] = "\x0c\x02\x61\x61\x61";
+   wchar_t wtmp[4];
+   unsigned long len, outlen;
    void *x, *y;
    ltc_asn1_list seq[2];
    ltc_asn1_list *l;
@@ -1421,6 +1423,11 @@ static void s_der_regression_test(void)
 
    len = sizeof(issue_507);
    SHOULD_FAIL(der_decode_sequence_flexi(issue_507, &len, &l));
+
+   len = sizeof(utf8_length);
+   outlen = sizeof(wtmp)/sizeof(wtmp[0]);
+   DO(der_decode_utf8_string(utf8_length, len, wtmp, &outlen));
+   ENSURE(outlen == 2);
 }
 
 static void der_toolong_test(void)