Commit 22cef6cb authored by Lev Walkin's avatar Lev Walkin

BMPString and UniversalString fuzz testing

parent e4a1625a
...@@ -2129,7 +2129,9 @@ emit_member_PER_constraints(arg_t *arg, asn1p_expr_t *expr, const char *pfx) { ...@@ -2129,7 +2129,9 @@ emit_member_PER_constraints(arg_t *arg, asn1p_expr_t *expr, const char *pfx) {
if((arg->flags & A1C_GEN_PER) if((arg->flags & A1C_GEN_PER)
&& (expr->combined_constraints && (expr->combined_constraints
|| etype == ASN_BASIC_ENUMERATED || etype == ASN_BASIC_ENUMERATED
|| etype == ASN_CONSTR_CHOICE) || etype == ASN_CONSTR_CHOICE
|| (etype & ASN_STRING_KM_MASK)
)
) { ) {
/* Fall through */ /* Fall through */
} else { } else {
...@@ -2978,10 +2980,11 @@ emit_type_DEF(arg_t *arg, asn1p_expr_t *expr, enum tvm_compat tv_mode, int tags_ ...@@ -2978,10 +2980,11 @@ emit_type_DEF(arg_t *arg, asn1p_expr_t *expr, enum tvm_compat tv_mode, int tags_
OUT(", "); OUT(", ");
if(arg->flags & A1C_GEN_PER) { if(arg->flags & A1C_GEN_PER) {
if(expr->combined_constraints if(expr->combined_constraints
|| expr->expr_type == ASN_BASIC_ENUMERATED || expr->expr_type == ASN_BASIC_ENUMERATED
|| expr->expr_type == ASN_CONSTR_CHOICE) { || expr->expr_type == ASN_CONSTR_CHOICE
OUT("&asn_PER_type_%s_constr_%d", || (expr->expr_type & ASN_STRING_KM_MASK)) {
OUT("&asn_PER_type_%s_constr_%d",
expr_id, expr->_type_unique_index); expr_id, expr->_type_unique_index);
} else { } else {
OUT("0"); OUT("0");
......
...@@ -1313,28 +1313,32 @@ OCTET_STRING_per_put_characters(asn_per_outp_t *po, const uint8_t *buf, ...@@ -1313,28 +1313,32 @@ OCTET_STRING_per_put_characters(asn_per_outp_t *po, const uint8_t *buf,
return per_put_many_bits(po, buf, unit_bits * units); return per_put_many_bits(po, buf, unit_bits * units);
} }
for(ub -= lb; buf < end; buf += bpc) { for(ub -= lb; buf < end; buf += bpc) {
int ch; int ch;
uint32_t value; uint32_t value;
switch(bpc) { switch(bpc) {
case 1: value = *(const uint8_t *)buf; break; case 1:
case 2: value = (buf[0] << 8) | buf[1]; break; value = *(const uint8_t *)buf;
case 4: value = (buf[0] << 24) | (buf[1] << 16) break;
| (buf[2] << 8) | buf[3]; break; case 2:
default: return -1; value = (buf[0] << 8) | buf[1];
} break;
ch = value - lb; case 4:
if(ch < 0 || ch > ub) { value = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
ASN_DEBUG("Character %d (0x%02x)" break;
" is out of range (%ld..%ld)", default:
*buf, *buf, lb, ub + lb); return -1;
return -1; }
} ch = value - lb;
if(per_put_few_bits(po, ch, unit_bits)) if(ch < 0 || ch > ub) {
return -1; ASN_DEBUG("Character %d (0x%02x) is out of range (%ld..%ld)", *buf,
} value, lb, ub + lb);
return -1;
}
if(per_put_few_bits(po, ch, unit_bits)) return -1;
}
return 0; return 0;
} }
static asn_per_constraints_t asn_DEF_OCTET_STRING_constraints = { static asn_per_constraints_t asn_DEF_OCTET_STRING_constraints = {
...@@ -1998,13 +2002,19 @@ OCTET_STRING_random_fill(const asn_TYPE_descriptor_t *td, void **sptr, ...@@ -1998,13 +2002,19 @@ OCTET_STRING_random_fill(const asn_TYPE_descriptor_t *td, void **sptr,
break; break;
case 2: case 2:
for(b = buf; b < bend; b += unit_bytes) { for(b = buf; b < bend; b += unit_bytes) {
*(uint16_t *)b = OCTET_STRING__random_char(clb, cub); uint32_t code = OCTET_STRING__random_char(clb, cub);
b[0] = code >> 8;
b[1] = code;
} }
*(uint16_t *)b = 0; *(uint16_t *)b = 0;
break; break;
case 4: case 4:
for(b = buf; b < bend; b += unit_bytes) { for(b = buf; b < bend; b += unit_bytes) {
*(uint32_t *)b = OCTET_STRING__random_char(clb, cub); uint32_t code = OCTET_STRING__random_char(clb, cub);
b[0] = code >> 24;
b[1] = code >> 16;
b[2] = code >> 8;
b[3] = code;
} }
*(uint32_t *)b = 0; *(uint32_t *)b = 0;
break; break;
......
/*- /*-
* Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved. * Copyright (c) 2003-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license. * Redistribution and modifications are permitted subject to BSD license.
*/ */
#include <asn_internal.h> #include <asn_internal.h>
...@@ -236,3 +236,36 @@ UniversalString_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel, ...@@ -236,3 +236,36 @@ UniversalString_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
return 0; return 0;
} }
/*
* Biased function for randomizing UCS-4 sequences.
*/
static size_t
UniversalString__random_char(uint8_t *b) {
uint32_t code;
switch(asn_random_between(0, 4)) {
case 0:
code = 0;
break;
case 1:
code = 1;
break;
case 2:
code = 0xd7ff; /* End of pre-surrogate block */
break;
case 3:
code = 0xe000; /* Beginning of post-surrogate block */
break;
case 4:
code = 0x10ffff;
break;
}
b[0] = code >> 24;
b[1] = code >> 16;
b[2] = code >> 8;
b[3] = code;
return 4;
}
...@@ -472,6 +472,7 @@ typedef IA5String_t Str1_t; ...@@ -472,6 +472,7 @@ typedef IA5String_t Str1_t;
/*** <<< FUNC-DECLS [Str1] >>> ***/ /*** <<< FUNC-DECLS [Str1] >>> ***/
extern asn_per_constraints_t asn_PER_type_Str1_constr_1;
extern asn_TYPE_descriptor_t asn_DEF_Str1; extern asn_TYPE_descriptor_t asn_DEF_Str1;
asn_struct_free_f Str1_free; asn_struct_free_f Str1_free;
asn_struct_print_f Str1_print; asn_struct_print_f Str1_print;
...@@ -490,6 +491,14 @@ per_type_encoder_f Str1_encode_uper; ...@@ -490,6 +491,14 @@ per_type_encoder_f Str1_encode_uper;
* so here we adjust the DEF accordingly. * so here we adjust the DEF accordingly.
*/ */
/*** <<< CTDEFS [Str1] >>> ***/
asn_per_constraints_t asn_PER_type_Str1_constr_1 CC_NOTUSED = {
{ APC_CONSTRAINED, 7, 7, 0, 127 } /* (0..127) */,
{ APC_SEMI_CONSTRAINED, -1, -1, 0, 0 } /* (SIZE(0..MAX)) */,
0, 0 /* No PER character map necessary */
};
/*** <<< STAT-DEFS [Str1] >>> ***/ /*** <<< STAT-DEFS [Str1] >>> ***/
static const ber_tlv_tag_t asn_DEF_Str1_tags_1[] = { static const ber_tlv_tag_t asn_DEF_Str1_tags_1[] = {
...@@ -505,7 +514,7 @@ asn_TYPE_descriptor_t asn_DEF_Str1 = { ...@@ -505,7 +514,7 @@ asn_TYPE_descriptor_t asn_DEF_Str1 = {
asn_DEF_Str1_tags_1, /* Same as above */ asn_DEF_Str1_tags_1, /* Same as above */
sizeof(asn_DEF_Str1_tags_1) sizeof(asn_DEF_Str1_tags_1)
/sizeof(asn_DEF_Str1_tags_1[0]), /* 1 */ /sizeof(asn_DEF_Str1_tags_1[0]), /* 1 */
{ 0, 0, IA5String_constraint }, { 0, &asn_PER_type_Str1_constr_1, IA5String_constraint },
0, 0, /* No members */ 0, 0, /* No members */
0 /* No specifics */ 0 /* No specifics */
}; };
......
...@@ -34,8 +34,10 @@ TESTS += bundles/07-VisibleString-bundle.txt ...@@ -34,8 +34,10 @@ TESTS += bundles/07-VisibleString-bundle.txt
TESTS += bundles/08-OBJECT-IDENTIFIER-bundle.txt TESTS += bundles/08-OBJECT-IDENTIFIER-bundle.txt
TESTS += bundles/09-RELATIVE-OID-bundle.txt TESTS += bundles/09-RELATIVE-OID-bundle.txt
TESTS += bundles/10-UTF8String-bundle.txt TESTS += bundles/10-UTF8String-bundle.txt
TESTS += bundles/11-UTCTime-bundle.txt TESTS += bundles/11-BMPString-bundle.txt
TESTS += bundles/12-GeneralizedTime-bundle.txt TESTS += bundles/12-UniversalString-bundle.txt
TESTS += bundles/13-UTCTime-bundle.txt
TESTS += bundles/14-GeneralizedTime-bundle.txt
EXTRA_DIST = \ EXTRA_DIST = \
random-test-driver.c \ random-test-driver.c \
......
UTF8String UTF8String
UTF8String (SIZE(0))
UTF8String (SIZE(1))
UTF8String (SIZE(3)) UTF8String (SIZE(3))
UTF8String (FROM("A".."Z")) UTF8String (FROM("A".."Z"))
UTF8String (FROM("A".."Z") INTERSECTION SIZE(0))
UTF8String (FROM("A".."Z") INTERSECTION SIZE(3)) UTF8String (FROM("A".."Z") INTERSECTION SIZE(3))
BMPString
BMPString (SIZE(0))
BMPString (SIZE(1))
BMPString (SIZE(3))
BMPString (FROM("A".."Z"))
BMPString (FROM("A".."Z") INTERSECTION SIZE(0))
BMPString (FROM("A".."Z") INTERSECTION SIZE(3))
UniversalString
UniversalString (SIZE(0))
UniversalString (SIZE(1))
UniversalString (SIZE(3))
UniversalString (FROM("A".."Z"))
UniversalString (FROM("A".."Z") INTERSECTION SIZE(0))
UniversalString (FROM("A".."Z") INTERSECTION SIZE(3))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment