asn1write: Test short and large buffers more systematically
Use the test-many-sizes framework for string writes as well (previously, it was only used for booleans and integers). This way, more edge cases are tested with less test code. This commit removes buffer overwrite checks. Instead of these checks, run the test suite under a memory sanitizer (which we do in our CI).
This commit is contained in:
parent
105031b1e1
commit
3f37dca794
2 changed files with 117 additions and 149 deletions
|
@ -82,56 +82,62 @@ mbedtls_asn1_write_mpi:"7bd1913fcfb652896209ad3e62f5d04a8dfc71eb1698543c52200bd7
|
|||
ASN.1 Write mpi, 256*8-1 bits
|
||||
mbedtls_asn1_write_mpi:"7bd1913fcfb652896209ad3e62f5d04a8dfc71eb1698543c52200bd7bbf3c11dd9ff57c299a2f4da172b3d5bd7e29affddf8859be7d50a45537a0df15b17af603d18803fd17134847cba78d83e64bf9fee58364d6124add0541da7bad331cd35fb48186a74bc502ddb967602401c0db02b19e5d38f09e8618fa7f6a1a3f738629baffdc63d9d70d396007d943fd64ae696e5b7e88f2c6d6ec322b461dbddd36efa91d990343b66419cf4832a22dc9ad13021185a1bf007989a50ba3bfd1152b8db899482d3ed498d1b9fae243a3cdae9530d8b29fdb684f70cdc0c9b8527265312603b405e67d59d4b1d654ddc3b7fd5515acb32440dc80903c8474a2c136c89":"028201007bd1913fcfb652896209ad3e62f5d04a8dfc71eb1698543c52200bd7bbf3c11dd9ff57c299a2f4da172b3d5bd7e29affddf8859be7d50a45537a0df15b17af603d18803fd17134847cba78d83e64bf9fee58364d6124add0541da7bad331cd35fb48186a74bc502ddb967602401c0db02b19e5d38f09e8618fa7f6a1a3f738629baffdc63d9d70d396007d943fd64ae696e5b7e88f2c6d6ec322b461dbddd36efa91d990343b66419cf4832a22dc9ad13021185a1bf007989a50ba3bfd1152b8db899482d3ed498d1b9fae243a3cdae9530d8b29fdb684f70cdc0c9b8527265312603b405e67d59d4b1d654ddc3b7fd5515acb32440dc80903c8474a2c136c89"
|
||||
|
||||
ASN.1 Write Octet String #0 (Empty string)
|
||||
mbedtls_asn1_write_octet_string:"":"0400":2:2
|
||||
ASN.1 Write OCTET STRING: length=0
|
||||
mbedtls_asn1_write_string:MBEDTLS_ASN1_OCTET_STRING:"":"0400"
|
||||
|
||||
ASN.1 Write Octet String #1 (Large buffer)
|
||||
mbedtls_asn1_write_octet_string:"AABBCC":"0403AABBCC":10:5
|
||||
ASN.1 Write OCTET STRING: length=1
|
||||
mbedtls_asn1_write_string:MBEDTLS_ASN1_OCTET_STRING:"41":"040141"
|
||||
|
||||
ASN.1 Write Octet String #2 (Buffer just fits)
|
||||
mbedtls_asn1_write_octet_string:"AABBCC":"0403AABBCC":5:5
|
||||
ASN.1 Write OCTET STRING: length=2
|
||||
mbedtls_asn1_write_string:MBEDTLS_ASN1_OCTET_STRING:"4142":"04024142"
|
||||
|
||||
ASN.1 Write Octet String #3 (Buffer too small for tag)
|
||||
mbedtls_asn1_write_octet_string:"AABBCC":"0403AABBCC":4:MBEDTLS_ERR_ASN1_BUF_TOO_SMALL
|
||||
ASN.1 Write OCTET STRING: length=127
|
||||
mbedtls_asn1_write_string:MBEDTLS_ASN1_OCTET_STRING:"99a66790856f7199641f55cadabb660aaed6aa0d9ef8cef4417118c6e8c6e15becbaa21c63faf48726e92357a38b3079a0b9d60be7457ec6552f900dd032577167c91e829927343c3a769b362db4de0ad2ffb8f13cc2eeca9e52dc557118baa88b857477595622bc301a1ae2150030d652c4a482cf88d0ded85d6731ff2d38":"047f99a66790856f7199641f55cadabb660aaed6aa0d9ef8cef4417118c6e8c6e15becbaa21c63faf48726e92357a38b3079a0b9d60be7457ec6552f900dd032577167c91e829927343c3a769b362db4de0ad2ffb8f13cc2eeca9e52dc557118baa88b857477595622bc301a1ae2150030d652c4a482cf88d0ded85d6731ff2d38"
|
||||
|
||||
ASN.1 Write Octet String #4 (Buffer too small for len)
|
||||
mbedtls_asn1_write_octet_string:"AABBCC":"0403AABBCC":3:MBEDTLS_ERR_ASN1_BUF_TOO_SMALL
|
||||
ASN.1 Write OCTET STRING: length=128
|
||||
mbedtls_asn1_write_string:MBEDTLS_ASN1_OCTET_STRING:"0199a66790856f7199641f55cadabb660aaed6aa0d9ef8cef4417118c6e8c6e15becbaa21c63faf48726e92357a38b3079a0b9d60be7457ec6552f900dd032577167c91e829927343c3a769b362db4de0ad2ffb8f13cc2eeca9e52dc557118baa88b857477595622bc301a1ae2150030d652c4a482cf88d0ded85d6731ff2d38":"0481800199a66790856f7199641f55cadabb660aaed6aa0d9ef8cef4417118c6e8c6e15becbaa21c63faf48726e92357a38b3079a0b9d60be7457ec6552f900dd032577167c91e829927343c3a769b362db4de0ad2ffb8f13cc2eeca9e52dc557118baa88b857477595622bc301a1ae2150030d652c4a482cf88d0ded85d6731ff2d38"
|
||||
|
||||
ASN.1 Write Octet String #5 (Buffer too small for string)
|
||||
mbedtls_asn1_write_octet_string:"AABBCC":"0403AABBCC":2:MBEDTLS_ERR_ASN1_BUF_TOO_SMALL
|
||||
ASN.1 Write OCTET STRING: length=255
|
||||
mbedtls_asn1_write_string:MBEDTLS_ASN1_OCTET_STRING:"633ed2cb0a2915dc4438a4c063017eb336cd9571d2a0585522c5073ca22a30ca7b8c9bd167d89ba1827bc6fb5d6ef6dcc52ee6eecc47e84ee0dd18fa3ebbdb6edfc679f037160d48d46a0d7e571335b24a28c8fd29b7f4a93d013b74e522bc1f5f605096bb99d438814b77b54d6dde608417b0a0ce9a8cb507fbeb95e9926b4bb6eec725599493d4b156ef3a5fd701426456029111c20f1d03c5d8999d2c042277ef91c5114a6c06218c1ba28d41ef08e4870d0cef260cba9de16d7d11ed5889b88fb93073746ebb158a4246cdb8a4ce403a5d1d598a0d11548f22070f833c1344d15e7a1445c133d19b8295b7c071bf2227178938031249d22d21c6f8e53d":"0481ff633ed2cb0a2915dc4438a4c063017eb336cd9571d2a0585522c5073ca22a30ca7b8c9bd167d89ba1827bc6fb5d6ef6dcc52ee6eecc47e84ee0dd18fa3ebbdb6edfc679f037160d48d46a0d7e571335b24a28c8fd29b7f4a93d013b74e522bc1f5f605096bb99d438814b77b54d6dde608417b0a0ce9a8cb507fbeb95e9926b4bb6eec725599493d4b156ef3a5fd701426456029111c20f1d03c5d8999d2c042277ef91c5114a6c06218c1ba28d41ef08e4870d0cef260cba9de16d7d11ed5889b88fb93073746ebb158a4246cdb8a4ce403a5d1d598a0d11548f22070f833c1344d15e7a1445c133d19b8295b7c071bf2227178938031249d22d21c6f8e53d"
|
||||
|
||||
ASN.1 Write Octet String #6 (l = 128, large buffer)
|
||||
mbedtls_asn1_write_octet_string:"000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F":"048180000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F":140:131
|
||||
ASN.1 Write OCTET STRING: length=256
|
||||
mbedtls_asn1_write_string:MBEDTLS_ASN1_OCTET_STRING:"5a633ed2cb0a2915dc4438a4c063017eb336cd9571d2a0585522c5073ca22a30ca7b8c9bd167d89ba1827bc6fb5d6ef6dcc52ee6eecc47e84ee0dd18fa3ebbdb6edfc679f037160d48d46a0d7e571335b24a28c8fd29b7f4a93d013b74e522bc1f5f605096bb99d438814b77b54d6dde608417b0a0ce9a8cb507fbeb95e9926b4bb6eec725599493d4b156ef3a5fd701426456029111c20f1d03c5d8999d2c042277ef91c5114a6c06218c1ba28d41ef08e4870d0cef260cba9de16d7d11ed5889b88fb93073746ebb158a4246cdb8a4ce403a5d1d598a0d11548f22070f833c1344d15e7a1445c133d19b8295b7c071bf2227178938031249d22d21c6f8e53d":"048201005a633ed2cb0a2915dc4438a4c063017eb336cd9571d2a0585522c5073ca22a30ca7b8c9bd167d89ba1827bc6fb5d6ef6dcc52ee6eecc47e84ee0dd18fa3ebbdb6edfc679f037160d48d46a0d7e571335b24a28c8fd29b7f4a93d013b74e522bc1f5f605096bb99d438814b77b54d6dde608417b0a0ce9a8cb507fbeb95e9926b4bb6eec725599493d4b156ef3a5fd701426456029111c20f1d03c5d8999d2c042277ef91c5114a6c06218c1ba28d41ef08e4870d0cef260cba9de16d7d11ed5889b88fb93073746ebb158a4246cdb8a4ce403a5d1d598a0d11548f22070f833c1344d15e7a1445c133d19b8295b7c071bf2227178938031249d22d21c6f8e53d"
|
||||
|
||||
ASN.1 Write Octet String #7 (l = 128, buffer just fits)
|
||||
mbedtls_asn1_write_octet_string:"000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F":"048180000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F":131:131
|
||||
ASN.1 Write UTF8 STRING: length=0
|
||||
mbedtls_asn1_write_string:MBEDTLS_ASN1_UTF8_STRING:"":"0c00"
|
||||
|
||||
ASN.1 Write Octet String #8 (l = 128, buffer too small for tag)
|
||||
mbedtls_asn1_write_octet_string:"000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F":"":130:MBEDTLS_ERR_ASN1_BUF_TOO_SMALL
|
||||
ASN.1 Write UTF8 STRING: length=1
|
||||
mbedtls_asn1_write_string:MBEDTLS_ASN1_UTF8_STRING:"41":"0c0141"
|
||||
|
||||
ASN.1 Write Octet String #9 (l = 128, buffer too small for len)
|
||||
mbedtls_asn1_write_octet_string:"000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F":"":129:MBEDTLS_ERR_ASN1_BUF_TOO_SMALL
|
||||
ASN.1 Write UTF8 STRING: length=128
|
||||
mbedtls_asn1_write_string:MBEDTLS_ASN1_UTF8_STRING:"0199a66790856f7199641f55cadabb660aaed6aa0d9ef8cef4417118c6e8c6e15becbaa21c63faf48726e92357a38b3079a0b9d60be7457ec6552f900dd032577167c91e829927343c3a769b362db4de0ad2ffb8f13cc2eeca9e52dc557118baa88b857477595622bc301a1ae2150030d652c4a482cf88d0ded85d6731ff2d38":"0c81800199a66790856f7199641f55cadabb660aaed6aa0d9ef8cef4417118c6e8c6e15becbaa21c63faf48726e92357a38b3079a0b9d60be7457ec6552f900dd032577167c91e829927343c3a769b362db4de0ad2ffb8f13cc2eeca9e52dc557118baa88b857477595622bc301a1ae2150030d652c4a482cf88d0ded85d6731ff2d38"
|
||||
|
||||
ASN.1 Write Octet String #9 (l = 128, buffer too small for string)
|
||||
mbedtls_asn1_write_octet_string:"000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F":"":127:MBEDTLS_ERR_ASN1_BUF_TOO_SMALL
|
||||
ASN.1 Write PRINTABLE STRING: length=0
|
||||
mbedtls_asn1_write_string:MBEDTLS_ASN1_PRINTABLE_STRING:"":"1300"
|
||||
|
||||
ASN.1 Write IA5 String #0 (Empty string)
|
||||
mbedtls_asn1_write_ia5_string:"":"1600":2:2
|
||||
ASN.1 Write PRINTABLE STRING: length=1
|
||||
mbedtls_asn1_write_string:MBEDTLS_ASN1_PRINTABLE_STRING:"41":"130141"
|
||||
|
||||
ASN.1 Write IA5 String #1 (Large buffer)
|
||||
mbedtls_asn1_write_ia5_string:"ABC":"1603414243":10:5
|
||||
ASN.1 Write PRINTABLE STRING: length=128
|
||||
mbedtls_asn1_write_string:MBEDTLS_ASN1_PRINTABLE_STRING:"0199a66790856f7199641f55cadabb660aaed6aa0d9ef8cef4417118c6e8c6e15becbaa21c63faf48726e92357a38b3079a0b9d60be7457ec6552f900dd032577167c91e829927343c3a769b362db4de0ad2ffb8f13cc2eeca9e52dc557118baa88b857477595622bc301a1ae2150030d652c4a482cf88d0ded85d6731ff2d38":"1381800199a66790856f7199641f55cadabb660aaed6aa0d9ef8cef4417118c6e8c6e15becbaa21c63faf48726e92357a38b3079a0b9d60be7457ec6552f900dd032577167c91e829927343c3a769b362db4de0ad2ffb8f13cc2eeca9e52dc557118baa88b857477595622bc301a1ae2150030d652c4a482cf88d0ded85d6731ff2d38"
|
||||
|
||||
ASN.1 Write IA5 String #2 (Buffer just fits)
|
||||
mbedtls_asn1_write_ia5_string:"ABC":"1603414243":5:5
|
||||
ASN.1 Write IA5 STRING: length=0
|
||||
mbedtls_asn1_write_string:MBEDTLS_ASN1_IA5_STRING:"":"1600"
|
||||
|
||||
ASN.1 Write IA5 String #3 (Buffer too small for tag)
|
||||
mbedtls_asn1_write_ia5_string:"ABC":"":4:MBEDTLS_ERR_ASN1_BUF_TOO_SMALL
|
||||
ASN.1 Write IA5 STRING: length=1
|
||||
mbedtls_asn1_write_string:MBEDTLS_ASN1_IA5_STRING:"41":"160141"
|
||||
|
||||
ASN.1 Write IA5 String #4 (Buffer too small for len)
|
||||
mbedtls_asn1_write_ia5_string:"ABC":"":3:MBEDTLS_ERR_ASN1_BUF_TOO_SMALL
|
||||
ASN.1 Write IA5 STRING: length=128
|
||||
mbedtls_asn1_write_string:MBEDTLS_ASN1_IA5_STRING:"0199a66790856f7199641f55cadabb660aaed6aa0d9ef8cef4417118c6e8c6e15becbaa21c63faf48726e92357a38b3079a0b9d60be7457ec6552f900dd032577167c91e829927343c3a769b362db4de0ad2ffb8f13cc2eeca9e52dc557118baa88b857477595622bc301a1ae2150030d652c4a482cf88d0ded85d6731ff2d38":"1681800199a66790856f7199641f55cadabb660aaed6aa0d9ef8cef4417118c6e8c6e15becbaa21c63faf48726e92357a38b3079a0b9d60be7457ec6552f900dd032577167c91e829927343c3a769b362db4de0ad2ffb8f13cc2eeca9e52dc557118baa88b857477595622bc301a1ae2150030d652c4a482cf88d0ded85d6731ff2d38"
|
||||
|
||||
ASN.1 Write IA5 String #5 (Buffer too small for string)
|
||||
mbedtls_asn1_write_ia5_string:"ABC":"":2:MBEDTLS_ERR_ASN1_BUF_TOO_SMALL
|
||||
ASN.1 Write tagged string: length=0
|
||||
mbedtls_asn1_write_string:MBEDTLS_ASN1_IA5_STRING | MBEDTLS_ASN1_CONTEXT_SPECIFIC:"":"9600"
|
||||
|
||||
ASN.1 Write tagged string: length=1
|
||||
mbedtls_asn1_write_string:MBEDTLS_ASN1_IA5_STRING | MBEDTLS_ASN1_CONTEXT_SPECIFIC:"41":"960141"
|
||||
|
||||
ASN.1 Write tagged string: length=128
|
||||
mbedtls_asn1_write_string:MBEDTLS_ASN1_IA5_STRING | MBEDTLS_ASN1_CONTEXT_SPECIFIC:"0199a66790856f7199641f55cadabb660aaed6aa0d9ef8cef4417118c6e8c6e15becbaa21c63faf48726e92357a38b3079a0b9d60be7457ec6552f900dd032577167c91e829927343c3a769b362db4de0ad2ffb8f13cc2eeca9e52dc557118baa88b857477595622bc301a1ae2150030d652c4a482cf88d0ded85d6731ff2d38":"9681800199a66790856f7199641f55cadabb660aaed6aa0d9ef8cef4417118c6e8c6e15becbaa21c63faf48726e92357a38b3079a0b9d60be7457ec6552f900dd032577167c91e829927343c3a769b362db4de0ad2ffb8f13cc2eeca9e52dc557118baa88b857477595622bc301a1ae2150030d652c4a482cf88d0ded85d6731ff2d38"
|
||||
|
||||
ASN.1 Write / Read Length #0 (Len = 0, short form)
|
||||
mbedtls_asn1_write_len:0:"00":1:1
|
||||
|
@ -176,73 +182,73 @@ ASN.1 Write / Read Length #12 (Len = 16909060, buffer too small)
|
|||
mbedtls_asn1_write_len:16909060:"8401020304":4:MBEDTLS_ERR_ASN1_BUF_TOO_SMALL
|
||||
|
||||
ASN.1 Write Named Bitstring / Unused bits #0
|
||||
test_asn1_write_bitstrings:"FF":8:"030200FF":4:1
|
||||
test_asn1_write_bitstrings:"FF":8:"030200FF":1
|
||||
|
||||
ASN.1 Write Named Bitstring / Unused bits #1
|
||||
test_asn1_write_bitstrings:"FE":8:"030201FE":4:1
|
||||
test_asn1_write_bitstrings:"FE":8:"030201FE":1
|
||||
|
||||
ASN.1 Write Named Bitstring / Unused bits #2
|
||||
test_asn1_write_bitstrings:"FC":7:"030202FC":4:1
|
||||
test_asn1_write_bitstrings:"FC":7:"030202FC":1
|
||||
|
||||
ASN.1 Write Named Bitstring / Unused bits #3
|
||||
test_asn1_write_bitstrings:"F8":8:"030203F8":4:1
|
||||
test_asn1_write_bitstrings:"F8":8:"030203F8":1
|
||||
|
||||
ASN.1 Write Named Bitstring / Unused bits #4
|
||||
test_asn1_write_bitstrings:"F0":6:"030204F0":4:1
|
||||
test_asn1_write_bitstrings:"F0":6:"030204F0":1
|
||||
|
||||
ASN.1 Write Named Bitstring / Unused bits #5
|
||||
test_asn1_write_bitstrings:"E0":6:"030205E0":4:1
|
||||
test_asn1_write_bitstrings:"E0":6:"030205E0":1
|
||||
|
||||
ASN.1 Write Named Bitstring / Unused bits #6
|
||||
test_asn1_write_bitstrings:"C0":8:"030206C0":4:1
|
||||
test_asn1_write_bitstrings:"C0":8:"030206C0":1
|
||||
|
||||
ASN.1 Write Named Bitstring / Unused bits #7
|
||||
test_asn1_write_bitstrings:"80":8:"03020780":4:1
|
||||
test_asn1_write_bitstrings:"80":8:"03020780":1
|
||||
|
||||
ASN.1 Write Named Bitstring / Empty bitstring
|
||||
test_asn1_write_bitstrings:"00":7:"030100":3:1
|
||||
test_asn1_write_bitstrings:"00":7:"030100":1
|
||||
|
||||
ASN.1 Write Named Bitstring / Empty bitstring (bits = 16)
|
||||
test_asn1_write_bitstrings:"0000":16:"030100":3:1
|
||||
test_asn1_write_bitstrings:"0000":16:"030100":1
|
||||
|
||||
ASN.1 Write Named Bitstring / Empty bitstring (bits = 24)
|
||||
test_asn1_write_bitstrings:"FFFFFF":0:"030100":3:1
|
||||
test_asn1_write_bitstrings:"FFFFFF":0:"030100":1
|
||||
|
||||
ASN.1 Write Named Bitstring / 15 trailing bits all unset
|
||||
test_asn1_write_bitstrings:"F88000":24:"030307F880":5:1
|
||||
test_asn1_write_bitstrings:"F88000":24:"030307F880":1
|
||||
|
||||
ASN.1 Write Named Bitstring / 15 trailing bits all set
|
||||
test_asn1_write_bitstrings:"F8FFFF":9:"030307F880":5:1
|
||||
test_asn1_write_bitstrings:"F8FFFF":9:"030307F880":1
|
||||
|
||||
ASN.1 Write Bitstring / Unused bits #0
|
||||
test_asn1_write_bitstrings:"FF":8:"030200FF":4:0
|
||||
test_asn1_write_bitstrings:"FF":8:"030200FF":0
|
||||
|
||||
ASN.1 Write Bitstring / Unused bits #1
|
||||
test_asn1_write_bitstrings:"FF":7:"030201FE":4:0
|
||||
test_asn1_write_bitstrings:"FF":7:"030201FE":0
|
||||
|
||||
ASN.1 Write Bitstring / Unused bits #2
|
||||
test_asn1_write_bitstrings:"FF":6:"030202FC":4:0
|
||||
test_asn1_write_bitstrings:"FF":6:"030202FC":0
|
||||
|
||||
ASN.1 Write Bitstring / Unused bits #3
|
||||
test_asn1_write_bitstrings:"FF":5:"030203F8":4:0
|
||||
test_asn1_write_bitstrings:"FF":5:"030203F8":0
|
||||
|
||||
ASN.1 Write Bitstring / Unused bits #4
|
||||
test_asn1_write_bitstrings:"FF":4:"030204F0":4:0
|
||||
test_asn1_write_bitstrings:"FF":4:"030204F0":0
|
||||
|
||||
ASN.1 Write Bitstring / Unused bits #5
|
||||
test_asn1_write_bitstrings:"FF":3:"030205E0":4:0
|
||||
test_asn1_write_bitstrings:"FF":3:"030205E0":0
|
||||
|
||||
ASN.1 Write Bitstring / Unused bits #6
|
||||
test_asn1_write_bitstrings:"FF":2:"030206C0":4:0
|
||||
test_asn1_write_bitstrings:"FF":2:"030206C0":0
|
||||
|
||||
ASN.1 Write Bitstring / Unused bits #7
|
||||
test_asn1_write_bitstrings:"FF":1:"03020780":4:0
|
||||
test_asn1_write_bitstrings:"FF":1:"03020780":0
|
||||
|
||||
ASN.1 Write Bitstring / 1 trailing bit (bits 15)
|
||||
test_asn1_write_bitstrings:"0003":15:"0303010002":5:0
|
||||
test_asn1_write_bitstrings:"0003":15:"0303010002":0
|
||||
|
||||
ASN.1 Write Bitstring / 0 bits
|
||||
test_asn1_write_bitstrings:"":0:"030100":3:0
|
||||
test_asn1_write_bitstrings:"":0:"030100":0
|
||||
|
||||
ASN.1 Write Bitstring / long string all bits unset except trailing bits
|
||||
test_asn1_write_bitstrings:"000000000007":45:"030703000000000000":9:0
|
||||
test_asn1_write_bitstrings:"000000000007":45:"030703000000000000":0
|
||||
|
|
|
@ -114,6 +114,8 @@ void mbedtls_asn1_write_mpi( data_t *val, data_t *expected )
|
|||
ret = mbedtls_asn1_write_mpi( &data.p, data.start, &mpi );
|
||||
if( ! generic_write_finish_step( &data, expected, ret ) )
|
||||
goto exit;
|
||||
if( expected->len > 10 && data.size == 8 )
|
||||
data.size = expected->len - 2;
|
||||
}
|
||||
|
||||
exit:
|
||||
|
@ -123,70 +125,49 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_asn1_write_octet_string( data_t * str, data_t * asn1,
|
||||
int buf_len, int result )
|
||||
void mbedtls_asn1_write_string( int tag, data_t *content, data_t *expected )
|
||||
{
|
||||
generic_write_data_t data = { NULL, NULL, NULL, NULL, 0 };
|
||||
int ret;
|
||||
unsigned char buf[150];
|
||||
size_t i;
|
||||
unsigned char *p;
|
||||
|
||||
memset( buf, GUARD_VAL, sizeof( buf ) );
|
||||
|
||||
|
||||
p = buf + GUARD_LEN + buf_len;
|
||||
|
||||
ret = mbedtls_asn1_write_octet_string( &p, buf + GUARD_LEN, str->x, str->len );
|
||||
|
||||
/* Check for buffer overwrite on both sides */
|
||||
for( i = 0; i < GUARD_LEN; i++ )
|
||||
for( data.size = 0; data.size < expected->len + 1; data.size++ )
|
||||
{
|
||||
TEST_ASSERT( buf[i] == GUARD_VAL );
|
||||
TEST_ASSERT( buf[GUARD_LEN + buf_len + i] == GUARD_VAL );
|
||||
if( ! generic_write_start_step( &data ) )
|
||||
goto exit;
|
||||
switch( tag )
|
||||
{
|
||||
case MBEDTLS_ASN1_OCTET_STRING:
|
||||
ret = mbedtls_asn1_write_octet_string(
|
||||
&data.p, data.start, content->x, content->len );
|
||||
break;
|
||||
case MBEDTLS_ASN1_UTF8_STRING:
|
||||
ret = mbedtls_asn1_write_utf8_string(
|
||||
&data.p, data.start,
|
||||
(const char *) content->x, content->len );
|
||||
break;
|
||||
case MBEDTLS_ASN1_PRINTABLE_STRING:
|
||||
ret = mbedtls_asn1_write_printable_string(
|
||||
&data.p, data.start,
|
||||
(const char *) content->x, content->len );
|
||||
break;
|
||||
case MBEDTLS_ASN1_IA5_STRING:
|
||||
ret = mbedtls_asn1_write_ia5_string(
|
||||
&data.p, data.start,
|
||||
(const char *) content->x, content->len );
|
||||
break;
|
||||
default:
|
||||
ret = mbedtls_asn1_write_tagged_string(
|
||||
&data.p, data.start, tag,
|
||||
(const char *) content->x, content->len );
|
||||
}
|
||||
if( ! generic_write_finish_step( &data, expected, ret ) )
|
||||
goto exit;
|
||||
if( expected->len > 10 && data.size == 8 )
|
||||
data.size = expected->len - 2;
|
||||
}
|
||||
|
||||
if( result >= 0 )
|
||||
{
|
||||
TEST_ASSERT( (size_t) ret == asn1->len );
|
||||
TEST_ASSERT( p + asn1->len == buf + GUARD_LEN + buf_len );
|
||||
|
||||
TEST_ASSERT( memcmp( p, asn1->x, asn1->len ) == 0 );
|
||||
}
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_asn1_write_ia5_string( char * str, data_t * asn1,
|
||||
int buf_len, int result )
|
||||
{
|
||||
int ret;
|
||||
unsigned char buf[150];
|
||||
size_t str_len;
|
||||
size_t i;
|
||||
unsigned char *p;
|
||||
|
||||
memset( buf, GUARD_VAL, sizeof( buf ) );
|
||||
|
||||
str_len = strlen( str );
|
||||
|
||||
p = buf + GUARD_LEN + buf_len;
|
||||
|
||||
ret = mbedtls_asn1_write_ia5_string( &p, buf + GUARD_LEN, str, str_len );
|
||||
|
||||
/* Check for buffer overwrite on both sides */
|
||||
for( i = 0; i < GUARD_LEN; i++ )
|
||||
{
|
||||
TEST_ASSERT( buf[i] == GUARD_VAL );
|
||||
TEST_ASSERT( buf[GUARD_LEN + buf_len + i] == GUARD_VAL );
|
||||
}
|
||||
|
||||
if( result >= 0 )
|
||||
{
|
||||
TEST_ASSERT( (size_t) ret == asn1->len );
|
||||
TEST_ASSERT( p + asn1->len == buf + GUARD_LEN + buf_len );
|
||||
|
||||
TEST_ASSERT( memcmp( p, asn1->x, asn1->len ) == 0 );
|
||||
}
|
||||
exit:
|
||||
mbedtls_free( data.output );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
|
@ -243,44 +224,25 @@ void mbedtls_asn1_write_len( int len, data_t * asn1, int buf_len,
|
|||
|
||||
/* BEGIN_CASE */
|
||||
void test_asn1_write_bitstrings( data_t *bitstring, int bits,
|
||||
data_t *expected_asn1, int result,
|
||||
int is_named )
|
||||
data_t *expected, int is_named )
|
||||
{
|
||||
generic_write_data_t data = { NULL, NULL, NULL, NULL, 0 };
|
||||
int ret;
|
||||
size_t i;
|
||||
unsigned char buf[150];
|
||||
unsigned char *p;
|
||||
int ( *func )( unsigned char **p, unsigned char *start,
|
||||
const unsigned char *buf, size_t bits ) =
|
||||
( is_named ? mbedtls_asn1_write_named_bitstring :
|
||||
mbedtls_asn1_write_bitstring );
|
||||
|
||||
memset( buf, GUARD_VAL, sizeof( buf ) );
|
||||
|
||||
p = buf + GUARD_LEN + expected_asn1->len;
|
||||
|
||||
if ( is_named == 0 )
|
||||
for( data.size = 0; data.size < expected->len + 1; data.size++ )
|
||||
{
|
||||
ret = mbedtls_asn1_write_bitstring( &p,
|
||||
buf,
|
||||
(unsigned char *)bitstring->x,
|
||||
(size_t) bits );
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = mbedtls_asn1_write_named_bitstring( &p,
|
||||
buf,
|
||||
(unsigned char *)bitstring->x,
|
||||
(size_t) bits );
|
||||
}
|
||||
TEST_ASSERT( ret == result );
|
||||
|
||||
/* Check for buffer overwrite on both sides */
|
||||
for( i = 0; i < GUARD_LEN; i++ )
|
||||
{
|
||||
TEST_ASSERT( buf[i] == GUARD_VAL );
|
||||
TEST_ASSERT( buf[GUARD_LEN + expected_asn1->len + i] == GUARD_VAL );
|
||||
if( ! generic_write_start_step( &data ) )
|
||||
goto exit;
|
||||
ret = ( *func )( &data.p, data.start, bitstring->x, bits );
|
||||
if( ! generic_write_finish_step( &data, expected, ret ) )
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if ( result >= 0 )
|
||||
{
|
||||
TEST_ASSERT( memcmp( p, expected_asn1->x, expected_asn1->len ) == 0 );
|
||||
}
|
||||
exit:
|
||||
mbedtls_free( data.output );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
|
Loading…
Reference in a new issue