Commit 16835b66 authored by Lev Walkin's avatar Lev Walkin
Browse files

better constraint failure reporting

parent 730b15a2
......@@ -7,6 +7,7 @@
* -t option added to asn1c to ease manual BER/CER/DER decoding.
* Added support COMPONENTS OF construct.
* Numerous parser fixes and enhancements.
* Better constraint failure reporting.
0.8.19: 2004-Aug-18
......
......@@ -109,7 +109,8 @@ asn1c_emit_constraint_checking_code(arg_t *arg) {
OUT("if(!sptr) {\n");
INDENT(+1);
OUT("_ASN_ERRLOG(app_errlog, app_key,\n");
OUT("\t\"%%s: value not given\", td->name);\n");
OUT("\t\"%%s: value not given (%%s:%%d)\",\n");
OUT("\ttd->name, __FILE__, __LINE__);\n");
OUT("return -1;\n");
INDENT(-1);
OUT("}\n");
......@@ -173,7 +174,8 @@ asn1c_emit_constraint_checking_code(arg_t *arg) {
OUT("} else {\n");
INDENT(+1);
OUT("_ASN_ERRLOG(app_errlog, app_key,\n");
OUT("\t\"%%s: constraint failed\", td->name);\n");
OUT("\t\"%%s: constraint failed (%%s:%%d)\",\n");
OUT("\ttd->name, __FILE__, __LINE__);\n");
OUT("return -1;\n");
INDENT(-1);
OUT("}\n");
......@@ -542,7 +544,8 @@ emit_value_determination_code(arg_t *arg, asn1p_expr_type_e etype) {
OUT("if(asn1_INTEGER2long(st, &value)) {\n");
INDENT(+1);
OUT("_ASN_ERRLOG(app_errlog, app_key,\n");
OUT("\t\"%%s: value too large\", td->name);\n");
OUT("\t\"%%s: value too large (%%s:%%d)\",\n");
OUT("\ttd->name, __FILE__, __LINE__);\n");
OUT("return -1;\n");
INDENT(-1);
OUT("}\n");
......
......@@ -39,18 +39,20 @@ BIT_STRING_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
if(st->size) {
if(st->size == 1 && st->buf[0] != 0) {
_ASN_ERRLOG(app_errlog, app_key,
"%s: invalid padding byte",
td->name);
"%s: invalid padding byte (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
} else {
_ASN_ERRLOG(app_errlog, app_key,
"%s: no padding byte", td->name);
"%s: no padding byte (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
} else {
_ASN_ERRLOG(app_errlog, app_key,
"%s: value not given", td->name);
"%s: value not given (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
......
......@@ -107,8 +107,8 @@ GeneralizedTime_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
tloc = asn_GT2time(st, 0, 0);
if(tloc == -1 && errno != EPERM) {
_ASN_ERRLOG(app_errlog, app_key,
"%s: Invalid time format: %s",
td->name, strerror(errno));
"%s: Invalid time format: %s (%s:%d)",
td->name, strerror(errno), __FILE__, __LINE__);
return -1;
}
......
......@@ -43,17 +43,18 @@ IA5String_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
if(*buf > 0x7F) {
_ASN_ERRLOG(app_errlog, app_key,
"%s: value byte %d out of range: "
"%d > 127",
"%d > 127 (%s:%d)",
td->name,
(buf - st->buf) + 1,
*buf
);
*buf,
__FILE__, __LINE__);
return -1;
}
}
} else {
_ASN_ERRLOG(app_errlog, app_key,
"%s: value not given", td->name);
"%s: value not given (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
......
......@@ -48,17 +48,18 @@ NumericString_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
continue;
}
_ASN_ERRLOG(app_errlog, app_key,
"%s: value byte %d "
"not in NumericString alphabet (%d)",
"%s: value byte %d (%d) "
"not in NumericString alphabet (%s:%d)",
td->name,
(buf - st->buf) + 1,
*buf
);
*buf,
__FILE__, __LINE__);
return -1;
}
} else {
_ASN_ERRLOG(app_errlog, app_key,
"%s: value not given", td->name);
"%s: value not given (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
......
......@@ -81,13 +81,15 @@ OBJECT_IDENTIFIER_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
if(st && st->buf) {
if(st->size < 1) {
_ASN_ERRLOG(app_errlog, app_key,
"%s: at least one numerical value expected",
td->name);
"%s: at least one numerical value "
"expected (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
} else {
_ASN_ERRLOG(app_errlog, app_key,
"%s: value not given", td->name);
"%s: value not given (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
......
......@@ -66,18 +66,20 @@ PrintableString_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
for(; buf < end; buf++) {
if(!_PrintableString_alphabet[*buf]) {
_ASN_ERRLOG(app_errlog, app_key,
"%s: value byte %d "
"not in PrintableString alphabet (%d)",
"%s: value byte %d (%d) "
"not in PrintableString alphabet "
"(%s:%d)",
td->name,
(buf - st->buf) + 1,
*buf
);
__FILE__, __LINE__);
return -1;
}
}
} else {
_ASN_ERRLOG(app_errlog, app_key,
"%s: value not given", td->name);
"%s: value not given (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
......
......@@ -48,8 +48,8 @@ UTCTime_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
tloc = asn_UT2time(st, 0, 0);
if(tloc == -1 && errno != EPERM) {
_ASN_ERRLOG(app_errlog, app_key,
"%s: Invalid time format: %s",
td->name, strerror(errno));
"%s: Invalid time format: %s (%s:%d)",
td->name, strerror(errno), __FILE__, __LINE__);
return -1;
}
......
......@@ -63,9 +63,10 @@ UTF8String_length(const UTF8String_t *st, const char *opt_type_name,
if(w) {
_ASN_ERRLOG(app_errlog, app_key,
"%s: UTF-8 expectation "
"failed at byte %d",
"failed at byte %d (%s:%d)",
opt_type_name,
(buf - st->buf) + 1);
(buf - st->buf) + 1,
__FILE__, __LINE__);
return -1;
}
want--;
......@@ -79,9 +80,10 @@ UTF8String_length(const UTF8String_t *st, const char *opt_type_name,
case 0:
_ASN_ERRLOG(app_errlog, app_key,
"%s: UTF-8 expectation"
"failed at byte %d",
"failed at byte %d (%s:%d)",
opt_type_name,
(buf - st->buf) + 1);
(buf - st->buf) + 1,
__FILE__, __LINE__);
return -1;
}
want = w - 1; /* Expect this much */
......@@ -92,8 +94,8 @@ UTF8String_length(const UTF8String_t *st, const char *opt_type_name,
/* If still want something, then something is wrong */
if(want) {
_ASN_ERRLOG(app_errlog, app_key,
"%s: truncated UTF-8 sequence",
opt_type_name);
"%s: truncated UTF-8 sequence (%s:%d)",
opt_type_name, __FILE__, __LINE__);
return -1;
}
......
......@@ -66,18 +66,19 @@ VisibleString_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
for(; buf < end; buf++) {
if(!_VisibleString_alphabet[*buf]) {
_ASN_ERRLOG(app_errlog, app_key,
"%s: value byte %d "
"not in VisibleString alphabet (%d)",
"%s: value byte %d (%d) "
"not in VisibleString alphabet (%s:%d)",
td->name,
(buf - st->buf) + 1,
*buf
);
*buf,
__FILE__, __LINE__);
return -1;
}
}
} else {
_ASN_ERRLOG(app_errlog, app_key,
"%s: value not given", td->name);
"%s: value not given (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
......
......@@ -481,7 +481,8 @@ CHOICE_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
if(!sptr) {
_ASN_ERRLOG(app_errlog, app_key,
"%s: value not given", td->name);
"%s: value not given (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
......@@ -515,7 +516,8 @@ CHOICE_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
}
} else {
_ASN_ERRLOG(app_errlog, app_key,
"%s: no CHOICE element given", td->name);
"%s: no CHOICE element given",
td->name, __FILE__, __LINE__);
return -1;
}
}
......
......@@ -644,7 +644,8 @@ SEQUENCE_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
if(!sptr) {
_ASN_ERRLOG(app_errlog, app_key,
"%s: value not given", td->name);
"%s: value not given (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
......
......@@ -659,7 +659,8 @@ SET_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
if(!sptr) {
_ASN_ERRLOG(app_errlog, app_key,
"%s: value not given", td->name);
"%s: value not given (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
......@@ -677,8 +678,9 @@ SET_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
&(specs->_mandatory_elements), edx)) {
_ASN_ERRLOG(app_errlog, app_key,
"%s: mandatory element "
"%s absent",
td->name, elm->name);
"%s absent (%s:%d)",
td->name, elm->name,
__FILE__, __LINE__);
return -1;
}
continue;
......
......@@ -518,7 +518,8 @@ SET_OF_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
if(!sptr) {
_ASN_ERRLOG(app_errlog, app_key,
"%s: value not given", td->name);
"%s: value not given (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
......
......@@ -261,7 +261,8 @@ memb_IA5String_1_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
if(!sptr) {
_ASN_ERRLOG(app_errlog, app_key,
"%s: value not given", td->name);
"%s: value not given (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
......@@ -271,7 +272,8 @@ memb_IA5String_1_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
return 0;
} else {
_ASN_ERRLOG(app_errlog, app_key,
"%s: constraint failed", td->name);
"%s: constraint failed (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
}
......
......@@ -40,7 +40,8 @@ memb_varsets_1_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
if(!sptr) {
_ASN_ERRLOG(app_errlog, app_key,
"%s: value not given", td->name);
"%s: value not given (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
......@@ -55,7 +56,8 @@ memb_varsets_1_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
return 0;
} else {
_ASN_ERRLOG(app_errlog, app_key,
"%s: constraint failed", td->name);
"%s: constraint failed (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
}
......@@ -187,7 +189,8 @@ memb_vparts_2_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
if(!sptr) {
_ASN_ERRLOG(app_errlog, app_key,
"%s: value not given", td->name);
"%s: value not given (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
......@@ -347,7 +350,8 @@ memb_vset_3_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
if(!sptr) {
_ASN_ERRLOG(app_errlog, app_key,
"%s: value not given", td->name);
"%s: value not given (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
......@@ -362,7 +366,8 @@ memb_vset_3_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
return 0;
} else {
_ASN_ERRLOG(app_errlog, app_key,
"%s: constraint failed", td->name);
"%s: constraint failed (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
}
......
......@@ -128,13 +128,15 @@ Int2_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
if(!sptr) {
_ASN_ERRLOG(app_errlog, app_key,
"%s: value not given", td->name);
"%s: value not given (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
if(asn1_INTEGER2long(st, &value)) {
_ASN_ERRLOG(app_errlog, app_key,
"%s: value too large", td->name);
"%s: value too large (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
......@@ -143,7 +145,8 @@ Int2_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
return 0;
} else {
_ASN_ERRLOG(app_errlog, app_key,
"%s: constraint failed", td->name);
"%s: constraint failed (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
}
......@@ -247,13 +250,15 @@ Int3_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
if(!sptr) {
_ASN_ERRLOG(app_errlog, app_key,
"%s: value not given", td->name);
"%s: value not given (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
if(asn1_INTEGER2long(st, &value)) {
_ASN_ERRLOG(app_errlog, app_key,
"%s: value too large", td->name);
"%s: value too large (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
......@@ -262,7 +267,8 @@ Int3_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
return 0;
} else {
_ASN_ERRLOG(app_errlog, app_key,
"%s: constraint failed", td->name);
"%s: constraint failed (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
}
......@@ -365,7 +371,8 @@ Int4_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
if(!sptr) {
_ASN_ERRLOG(app_errlog, app_key,
"%s: value not given", td->name);
"%s: value not given (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
......@@ -479,13 +486,15 @@ Int5_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
if(!sptr) {
_ASN_ERRLOG(app_errlog, app_key,
"%s: value not given", td->name);
"%s: value not given (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
if(asn1_INTEGER2long(st, &value)) {
_ASN_ERRLOG(app_errlog, app_key,
"%s: value too large", td->name);
"%s: value too large (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
......@@ -494,7 +503,8 @@ Int5_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
return 0;
} else {
_ASN_ERRLOG(app_errlog, app_key,
"%s: constraint failed", td->name);
"%s: constraint failed (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
}
......@@ -597,7 +607,8 @@ ExtensibleExtensions_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
if(!sptr) {
_ASN_ERRLOG(app_errlog, app_key,
"%s: value not given", td->name);
"%s: value not given (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
......@@ -827,7 +838,8 @@ Str2_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
if(!sptr) {
_ASN_ERRLOG(app_errlog, app_key,
"%s: value not given", td->name);
"%s: value not given (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
......@@ -839,7 +851,8 @@ Str2_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
return 0;
} else {
_ASN_ERRLOG(app_errlog, app_key,
"%s: constraint failed", td->name);
"%s: constraint failed (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
}
......@@ -970,7 +983,8 @@ Str3_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
if(!sptr) {
_ASN_ERRLOG(app_errlog, app_key,
"%s: value not given", td->name);
"%s: value not given (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
......@@ -982,7 +996,8 @@ Str3_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
return 0;
} else {
_ASN_ERRLOG(app_errlog, app_key,
"%s: constraint failed", td->name);
"%s: constraint failed (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
}
......@@ -1101,7 +1116,8 @@ PER_Visible_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
if(!sptr) {
_ASN_ERRLOG(app_errlog, app_key,
"%s: value not given", td->name);
"%s: value not given (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
......@@ -1111,7 +1127,8 @@ PER_Visible_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
return 0;
} else {
_ASN_ERRLOG(app_errlog, app_key,
"%s: constraint failed", td->name);
"%s: constraint failed (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
}
......@@ -1230,7 +1247,8 @@ PER_Visible_2_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
if(!sptr) {
_ASN_ERRLOG(app_errlog, app_key,
"%s: value not given", td->name);
"%s: value not given (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
......@@ -1240,7 +1258,8 @@ PER_Visible_2_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
return 0;
} else {
_ASN_ERRLOG(app_errlog, app_key,
"%s: constraint failed", td->name);
"%s: constraint failed (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
}
......@@ -1359,7 +1378,8 @@ Not_PER_Visible_1_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
if(!sptr) {
_ASN_ERRLOG(app_errlog, app_key,
"%s: value not given", td->name);
"%s: value not given (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
......@@ -1369,7 +1389,8 @@ Not_PER_Visible_1_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
return 0;
} else {
_ASN_ERRLOG(app_errlog, app_key,
"%s: constraint failed", td->name);
"%s: constraint failed (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
}
......@@ -1472,7 +1493,8 @@ Not_PER_Visible_2_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
if(!sptr) {
_ASN_ERRLOG(app_errlog, app_key,
"%s: value not given", td->name);
"%s: value not given (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
......@@ -1585,7 +1607,8 @@ Not_PER_Visible_3_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
if(!sptr) {
_ASN_ERRLOG(app_errlog, app_key,
"%s: value not given", td->name);
"%s: value not given (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
......@@ -1715,7 +1738,8 @@ SIZE_but_not_FROM_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
if(!sptr) {
_ASN_ERRLOG(app_errlog, app_key,
"%s: value not given", td->name);
"%s: value not given (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
......@@ -1727,7 +1751,8 @@ SIZE_but_not_FROM_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
return 0;
} else {
_ASN_ERRLOG(app_errlog, app_key,
"%s: constraint failed", td->name);
"%s: constraint failed (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
}
......@@ -1847,7 +1872,8 @@ SIZE_and_FROM_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
if(!sptr) {
_ASN_ERRLOG(app_errlog, app_key,
"%s: value not given", td->name);
"%s: value not given (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
......@@ -1859,7 +1885,8 @@ SIZE_and_FROM_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
return 0;
} else {
_ASN_ERRLOG(app_errlog, app_key,
"%s: constraint failed", td->name);
"%s: constraint failed (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
}
......@@ -1978,7 +2005,8 @@ Neither_SIZE_nor_FROM_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
if(!sptr) {
_ASN_ERRLOG(app_errlog, app_key,
"%s: value not given", td->name);
"%s: value not given (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
......@@ -1988,7 +2016,8 @@ Neither_SIZE_nor_FROM_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
return 0;
} else {
_ASN_ERRLOG(app_errlog, app_key,
"%s: constraint failed", td->name);