mirror of https://gerrit.osmocom.org/asn1c
PER decoding of open types fix
This commit is contained in:
parent
ffe79f4450
commit
190419b23c
|
@ -0,0 +1,59 @@
|
|||
#undef NDEBUG
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "T.h"
|
||||
#include "per_opentype.h"
|
||||
|
||||
int
|
||||
main() {
|
||||
asn_per_data_t pd;
|
||||
asn_per_outp_t po;
|
||||
asn_dec_rval_t rv;
|
||||
T_t t;
|
||||
T_t *t2 = 0;
|
||||
size_t i;
|
||||
|
||||
memset(&po, 0, sizeof po);
|
||||
po.buffer = po.tmpspace;
|
||||
po.nbits = sizeof(po.tmpspace) * 8;
|
||||
|
||||
memset(&t, 0, sizeof t);
|
||||
|
||||
printf("Checking uper_open_type_put():\n");
|
||||
assert(0 == uper_open_type_put(&asn_DEF_T, 0, &t, &po));
|
||||
assert(po.nbits == (-1 + sizeof(po.tmpspace)) * 8);
|
||||
printf("po{nboff=%d; nbits=%d; buffer=%p; tmpspace=%p}\n",
|
||||
po.nboff, po.nbits, po.buffer, po.tmpspace);
|
||||
/* One byte length and one byte 0x00 */
|
||||
assert( (po.nboff == 8 && po.buffer == &po.tmpspace[1])
|
||||
|| (po.nboff == 0 && po.buffer == &po.tmpspace[2]));
|
||||
assert(po.tmpspace[0] == 0x01);
|
||||
assert(po.tmpspace[1] == 0x00);
|
||||
|
||||
printf("\nChecking uper_open_type_get():\n");
|
||||
for(i = 0; i < 16; i++) {
|
||||
FREEMEM(t2); t2 = 0;
|
||||
memset(&pd, 0, sizeof pd);
|
||||
pd.buffer = po.tmpspace;
|
||||
pd.nboff = 0;
|
||||
pd.nbits = i;
|
||||
rv = uper_open_type_get(0, &asn_DEF_T, 0, (void **)&t2, &pd);
|
||||
assert(rv.code == RC_WMORE);
|
||||
}
|
||||
|
||||
memset(&pd, 0, sizeof pd);
|
||||
pd.buffer = po.tmpspace;
|
||||
pd.nboff = 0;
|
||||
pd.nbits = 16;
|
||||
rv = uper_open_type_get(0, &asn_DEF_T, 0, (void **)&t2, &pd);
|
||||
assert(rv.code == RC_OK);
|
||||
assert( (pd.nboff == 8 && pd.buffer == &po.tmpspace[1])
|
||||
|| (pd.nboff == 16 && pd.buffer == &po.tmpspace[0]));
|
||||
assert(pd.nboff + pd.nbits == 16);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -38,6 +38,8 @@ uper_open_type_put(asn_TYPE_descriptor_t *td, asn_per_constraints_t *constraints
|
|||
|
||||
for(bptr = buf, toGo = size; toGo;) {
|
||||
ssize_t maySave = uper_put_length(po, toGo);
|
||||
ASN_DEBUG("Prepending length %d to %s and allowing to save %d",
|
||||
(int)size, td->name, (int)maySave);
|
||||
if(maySave < 0) break;
|
||||
if(per_put_many_bits(po, bptr, maySave * 8)) break;
|
||||
bptr = (char *)bptr + maySave;
|
||||
|
@ -106,8 +108,9 @@ uper_open_type_get_simple(asn_codec_ctx_t *ctx, asn_TYPE_descriptor_t *td,
|
|||
if(rv.code == RC_OK) {
|
||||
/* Check padding validity */
|
||||
padding = spd.nbits - spd.nboff;
|
||||
if (((rv.consumed == 0 && padding == 8) /* X.691#10.1.3 */
|
||||
|| padding < 8) &&
|
||||
if ((padding < 8 ||
|
||||
/* X.691#10.1.3 */
|
||||
(spd.nboff == 0 && spd.nbits == 8 && spd.buffer == buf)) &&
|
||||
per_get_few_bits(&spd, padding) == 0) {
|
||||
/* Everything is cool */
|
||||
FREEMEM(buf);
|
||||
|
|
|
@ -314,7 +314,7 @@ per_put_few_bits(asn_per_outp_t *po, uint32_t bits, int obits) {
|
|||
|
||||
ASN_DEBUG("[PER out %d %u/%x (t=%d,o=%d) %x&%x=%x]", obits,
|
||||
(int)bits, (int)bits,
|
||||
po->nboff - obits, off, buf[0], omsk&0xff, buf[0] & omsk);
|
||||
po->nboff, off, buf[0], omsk&0xff, buf[0] & omsk);
|
||||
|
||||
if(off <= 8) /* Completely within 1 byte */
|
||||
po->nboff = off,
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
|
||||
-- OK: Everything is fine
|
||||
|
||||
-- iso.org.dod.internet.private.enterprise (1.3.6.1.4.1)
|
||||
-- .spelio.software.asn1c.test (9363.1.5.1)
|
||||
-- .131
|
||||
|
||||
ModulePERLong
|
||||
{ iso org(3) dod(6) internet (1) private(4) enterprise(1)
|
||||
spelio(9363) software(1) asn1c(5) test(1) 131 }
|
||||
DEFINITIONS AUTOMATIC TAGS ::=
|
||||
BEGIN
|
||||
|
||||
T ::= SEQUENCE { } -- Empty sequence
|
||||
|
||||
END
|
|
@ -0,0 +1,55 @@
|
|||
|
||||
/*** <<< INCLUDES [T] >>> ***/
|
||||
|
||||
#include <constr_SEQUENCE.h>
|
||||
|
||||
/*** <<< TYPE-DECLS [T] >>> ***/
|
||||
|
||||
typedef struct T {
|
||||
|
||||
/* Context for parsing across buffer boundaries */
|
||||
asn_struct_ctx_t _asn_ctx;
|
||||
} T_t;
|
||||
|
||||
/*** <<< FUNC-DECLS [T] >>> ***/
|
||||
|
||||
extern asn_TYPE_descriptor_t asn_DEF_T;
|
||||
|
||||
/*** <<< STAT-DEFS [T] >>> ***/
|
||||
|
||||
static ber_tlv_tag_t asn_DEF_T_tags_1[] = {
|
||||
(ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
|
||||
};
|
||||
static asn_SEQUENCE_specifics_t asn_SPC_T_specs_1 = {
|
||||
sizeof(struct T),
|
||||
offsetof(struct T, _asn_ctx),
|
||||
0, /* No top level tags */
|
||||
0, /* No tags in the map */
|
||||
0, 0, 0, /* Optional elements (not needed) */
|
||||
-1, /* Start extensions */
|
||||
-1 /* Stop extensions */
|
||||
};
|
||||
asn_TYPE_descriptor_t asn_DEF_T = {
|
||||
"T",
|
||||
"T",
|
||||
SEQUENCE_free,
|
||||
SEQUENCE_print,
|
||||
SEQUENCE_constraint,
|
||||
SEQUENCE_decode_ber,
|
||||
SEQUENCE_encode_der,
|
||||
SEQUENCE_decode_xer,
|
||||
SEQUENCE_encode_xer,
|
||||
SEQUENCE_decode_uper,
|
||||
SEQUENCE_encode_uper,
|
||||
0, /* Use generic outmost tag fetcher */
|
||||
asn_DEF_T_tags_1,
|
||||
sizeof(asn_DEF_T_tags_1)
|
||||
/sizeof(asn_DEF_T_tags_1[0]), /* 1 */
|
||||
asn_DEF_T_tags_1, /* Same as above */
|
||||
sizeof(asn_DEF_T_tags_1)
|
||||
/sizeof(asn_DEF_T_tags_1[0]), /* 1 */
|
||||
0, /* No PER visible constraints */
|
||||
0, 0, /* No members */
|
||||
&asn_SPC_T_specs_1 /* Additional specs */
|
||||
};
|
||||
|
Loading…
Reference in New Issue