handle BER octet string, remove EoD tag before parsing content of a INDEF encoding to the greedy encodings in inside (like ANY) will swallow the EoD
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@24186 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -230,7 +230,7 @@ range_check(const char *name,
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
decode_type (const char *name, const Type *t, int optional,
|
decode_type (const char *name, const Type *t, int optional,
|
||||||
const char *forwstr, const char *tmpstr)
|
const char *forwstr, const char *tmpstr, const char *dertype)
|
||||||
{
|
{
|
||||||
switch (t->type) {
|
switch (t->type) {
|
||||||
case TType: {
|
case TType: {
|
||||||
@@ -289,7 +289,17 @@ decode_type (const char *name, const Type *t, int optional,
|
|||||||
decode_primitive ("enumerated", name, forwstr);
|
decode_primitive ("enumerated", name, forwstr);
|
||||||
break;
|
break;
|
||||||
case TOctetString:
|
case TOctetString:
|
||||||
|
if (dertype) {
|
||||||
|
fprintf(codefile,
|
||||||
|
"if (%s == CONS) {\n",
|
||||||
|
dertype);
|
||||||
|
decode_primitive("octet_string_ber", name, forwstr);
|
||||||
|
fprintf(codefile,
|
||||||
|
"} else {\n");
|
||||||
|
}
|
||||||
decode_primitive ("octet_string", name, forwstr);
|
decode_primitive ("octet_string", name, forwstr);
|
||||||
|
if (dertype)
|
||||||
|
fprintf(codefile, "}\n");
|
||||||
if (t->range)
|
if (t->range)
|
||||||
range_check(name, "length", forwstr, t->range);
|
range_check(name, "length", forwstr, t->range);
|
||||||
break;
|
break;
|
||||||
@@ -340,7 +350,7 @@ decode_type (const char *name, const Type *t, int optional,
|
|||||||
name, m->gen_name);
|
name, m->gen_name);
|
||||||
if (s == NULL)
|
if (s == NULL)
|
||||||
errx(1, "malloc");
|
errx(1, "malloc");
|
||||||
decode_type (s, m->type, m->optional, forwstr, m->gen_name);
|
decode_type (s, m->type, m->optional, forwstr, m->gen_name, NULL);
|
||||||
free (s);
|
free (s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -382,7 +392,7 @@ decode_type (const char *name, const Type *t, int optional,
|
|||||||
"%s = calloc(1, sizeof(*%s));\n"
|
"%s = calloc(1, sizeof(*%s));\n"
|
||||||
"if (%s == NULL) { e = ENOMEM; %s; }\n",
|
"if (%s == NULL) { e = ENOMEM; %s; }\n",
|
||||||
s, s, s, forwstr);
|
s, s, s, forwstr);
|
||||||
decode_type (s, m->type, 0, forwstr, m->gen_name);
|
decode_type (s, m->type, 0, forwstr, m->gen_name, NULL);
|
||||||
free (s);
|
free (s);
|
||||||
|
|
||||||
fprintf(codefile, "members |= (1 << %d);\n", memno);
|
fprintf(codefile, "members |= (1 << %d);\n", memno);
|
||||||
@@ -458,7 +468,7 @@ decode_type (const char *name, const Type *t, int optional,
|
|||||||
asprintf (&sname, "%s_s_of", tmpstr);
|
asprintf (&sname, "%s_s_of", tmpstr);
|
||||||
if (sname == NULL)
|
if (sname == NULL)
|
||||||
errx(1, "malloc");
|
errx(1, "malloc");
|
||||||
decode_type (n, t->subtype, 0, forwstr, sname);
|
decode_type (n, t->subtype, 0, forwstr, sname, NULL);
|
||||||
fprintf (codefile,
|
fprintf (codefile,
|
||||||
"(%s)->len++;\n"
|
"(%s)->len++;\n"
|
||||||
"len = %s_origlen - ret;\n"
|
"len = %s_origlen - ret;\n"
|
||||||
@@ -480,21 +490,36 @@ decode_type (const char *name, const Type *t, int optional,
|
|||||||
decode_primitive ("general_string", name, forwstr);
|
decode_primitive ("general_string", name, forwstr);
|
||||||
break;
|
break;
|
||||||
case TTag:{
|
case TTag:{
|
||||||
char *tname;
|
char *tname, *typestring;
|
||||||
|
char *ide = NULL;
|
||||||
|
|
||||||
|
asprintf(&typestring, "%s_type", tmpstr);
|
||||||
|
|
||||||
fprintf(codefile,
|
fprintf(codefile,
|
||||||
"{\n"
|
"{\n"
|
||||||
"size_t %s_datalen, %s_oldlen;\n",
|
"size_t %s_datalen, %s_oldlen;\n"
|
||||||
tmpstr, tmpstr);
|
"Der_type %s;\n",
|
||||||
|
tmpstr, tmpstr, typestring);
|
||||||
if(dce_fix)
|
if(dce_fix)
|
||||||
fprintf(codefile,
|
fprintf(codefile,
|
||||||
"int dce_fix;\n");
|
"int dce_fix;\n");
|
||||||
fprintf(codefile, "e = der_match_tag_and_length(p, len, %s, %s, %s, "
|
|
||||||
|
fprintf(codefile, "e = der_match_tag_and_length2(p, len, %s, &%s, %s, "
|
||||||
"&%s_datalen, &l);\n",
|
"&%s_datalen, &l);\n",
|
||||||
classname(t->tag.tagclass),
|
classname(t->tag.tagclass),
|
||||||
is_primitive_type(t->subtype->type) ? "PRIM" : "CONS",
|
typestring,
|
||||||
valuename(t->tag.tagclass, t->tag.tagvalue),
|
valuename(t->tag.tagclass, t->tag.tagvalue),
|
||||||
tmpstr);
|
tmpstr);
|
||||||
|
|
||||||
|
/* XXX hardcode for now */
|
||||||
|
if (dce_fix && t->subtype->type == TOctetString) {
|
||||||
|
ide = typestring;
|
||||||
|
} else {
|
||||||
|
fprintf(codefile,
|
||||||
|
"if (%s != %s) { e = ASN1_BAD_ID; }\n",
|
||||||
|
typestring, is_primitive_type(t->subtype->type) ? "PRIM" : "CONS");
|
||||||
|
}
|
||||||
|
|
||||||
if(optional) {
|
if(optional) {
|
||||||
fprintf(codefile,
|
fprintf(codefile,
|
||||||
"if(e) {\n"
|
"if(e) {\n"
|
||||||
@@ -513,8 +538,9 @@ decode_type (const char *name, const Type *t, int optional,
|
|||||||
if(dce_fix)
|
if(dce_fix)
|
||||||
fprintf (codefile,
|
fprintf (codefile,
|
||||||
"if((dce_fix = _heim_fix_dce(%s_datalen, &len)) < 0)\n"
|
"if((dce_fix = _heim_fix_dce(%s_datalen, &len)) < 0)\n"
|
||||||
"{ e = ASN1_BAD_FORMAT; %s; }\n",
|
"{ e = ASN1_BAD_FORMAT; %s; }\n"
|
||||||
tmpstr, forwstr);
|
"if (dce_fix) { if (len < 2) { e = ASN1_OVERRUN; %s; } len -= 2; }",
|
||||||
|
tmpstr, forwstr, forwstr);
|
||||||
else
|
else
|
||||||
fprintf(codefile,
|
fprintf(codefile,
|
||||||
"if (%s_datalen > len) { e = ASN1_OVERRUN; %s; }\n"
|
"if (%s_datalen > len) { e = ASN1_OVERRUN; %s; }\n"
|
||||||
@@ -522,10 +548,11 @@ decode_type (const char *name, const Type *t, int optional,
|
|||||||
asprintf (&tname, "%s_Tag", tmpstr);
|
asprintf (&tname, "%s_Tag", tmpstr);
|
||||||
if (tname == NULL)
|
if (tname == NULL)
|
||||||
errx(1, "malloc");
|
errx(1, "malloc");
|
||||||
decode_type (name, t->subtype, 0, forwstr, tname);
|
decode_type (name, t->subtype, 0, forwstr, tname, ide);
|
||||||
if(dce_fix)
|
if(dce_fix)
|
||||||
fprintf(codefile,
|
fprintf(codefile,
|
||||||
"if(dce_fix){\n"
|
"if(dce_fix){\n"
|
||||||
|
"len += 2;\n"
|
||||||
"e = der_match_tag_and_length (p, len, "
|
"e = der_match_tag_and_length (p, len, "
|
||||||
"(Der_class)0,(Der_type)0, UT_EndOfContent, "
|
"(Der_class)0,(Der_type)0, UT_EndOfContent, "
|
||||||
"&%s_datalen, &l);\n"
|
"&%s_datalen, &l);\n"
|
||||||
@@ -540,6 +567,7 @@ decode_type (const char *name, const Type *t, int optional,
|
|||||||
fprintf(codefile,
|
fprintf(codefile,
|
||||||
"}\n");
|
"}\n");
|
||||||
free(tname);
|
free(tname);
|
||||||
|
free(typestring);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TChoice: {
|
case TChoice: {
|
||||||
@@ -573,7 +601,7 @@ decode_type (const char *name, const Type *t, int optional,
|
|||||||
name, m->gen_name);
|
name, m->gen_name);
|
||||||
if (s == NULL)
|
if (s == NULL)
|
||||||
errx(1, "malloc");
|
errx(1, "malloc");
|
||||||
decode_type (s, m->type, m->optional, forwstr, m->gen_name);
|
decode_type (s, m->type, m->optional, forwstr, m->gen_name, NULL);
|
||||||
fprintf(codefile,
|
fprintf(codefile,
|
||||||
"(%s)->element = %s;\n",
|
"(%s)->element = %s;\n",
|
||||||
name, m->label);
|
name, m->label);
|
||||||
@@ -695,7 +723,7 @@ generate_type_decode (const Symbol *s)
|
|||||||
fprintf (codefile, "\n");
|
fprintf (codefile, "\n");
|
||||||
fprintf (codefile, "memset(data, 0, sizeof(*data));\n"); /* hack to avoid `unused variable' */
|
fprintf (codefile, "memset(data, 0, sizeof(*data));\n"); /* hack to avoid `unused variable' */
|
||||||
|
|
||||||
decode_type ("data", s->type, 0, "goto fail", "Top");
|
decode_type ("data", s->type, 0, "goto fail", "Top", NULL);
|
||||||
if (preserve)
|
if (preserve)
|
||||||
fprintf (codefile,
|
fprintf (codefile,
|
||||||
"data->_save.data = calloc(1, ret);\n"
|
"data->_save.data = calloc(1, ret);\n"
|
||||||
|
Reference in New Issue
Block a user