Closed ljy5490 closed 5 years ago
Hi @ljy5490,
Could you provide all asn1 files?
Hi @ljy5490,
It's crashing because of this rather strange information object set definition in other
parameter.
Authentication-value ::= CHOICE {
charstring [0] IMPLICIT GraphicString,
bitstring [1] IMPLICIT BIT STRING,
external [2] IMPLICIT EXTERNAL,
other
[3] IMPLICIT SEQUENCE {other-mechanism-name
MECHANISM-NAME.&id({ObjectSet}),
other-mechanism-value
MECHANISM-NAME.&Type
({ObjectSet}{@.other-mechanism-name})}
}
If you don't need the other
parameter a dirty workaround is to change the definition to
Authentication-value ::= CHOICE {
charstring [0] IMPLICIT GraphicString,
bitstring [1] IMPLICIT BIT STRING,
external [2] IMPLICIT EXTERNAL,
other
[3] IMPLICIT SEQUENCE {other-mechanism-name INTEGER,
other-mechanism-value ANY}
}
Here is a gdb backtrace
(gdb) bt
#0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1 0x00007ffff7a385b9 in __GI_abort () at abort.c:79
#2 0x00007ffff7a38491 in __assert_fail_base (fmt=0x7ffff7b9b048 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n",
assertion=0x44f4d8 "arg->target->target == OT_TYPE_DECLS || arg->target->target == OT_FWD_DEFS", file=0x44d274 "asn1c_C.c", line=386,
function=0x4506c0 <__PRETTY_FUNCTION__.5460> "asn1c_lang_C_type_SEQUENCE") at assert.c:92
#3 0x00007ffff7a46612 in __GI___assert_fail (
assertion=assertion@entry=0x44f4d8 "arg->target->target == OT_TYPE_DECLS || arg->target->target == OT_FWD_DEFS",
file=file@entry=0x44d274 "asn1c_C.c", line=line@entry=386,
function=function@entry=0x4506c0 <__PRETTY_FUNCTION__.5460> "asn1c_lang_C_type_SEQUENCE") at assert.c:101
#4 0x00000000004308c2 in asn1c_lang_C_type_SEQUENCE (arg=0x7fffffffd280) at asn1c_C.c:386
#5 0x0000000000421312 in asn1c_compile_expr (arg=0x7fffffffd280, opt_ioc=0x0) at asn1compiler.c:132
#6 0x000000000042e597 in asn1c_lang_C_type_CHOICE (arg=0x7fffffffd380) at asn1c_C.c:1012
#7 0x0000000000421312 in asn1c_compile_expr (arg=arg@entry=0x7fffffffd380, opt_ioc=opt_ioc@entry=0x0) at asn1compiler.c:132
#8 0x00000000004215f9 in asn1_compile (asn=asn@entry=0x69ef00, datadir=datadir@entry=0x7fffffffd9b1 "../skeletons/",
destdir=destdir@entry=0x445bee "", flags=flags@entry=(A1C_NO_C99 | A1C_GEN_OER | A1C_GEN_PER | A1C_GEN_EXAMPLE), argc=4, optc=3,
argv=0x7fffffffd608) at asn1compiler.c:50
#9 0x00000000004021c4 in main (ac=1, av=0x7fffffffd620) at asn1c.c:417
(gdb) f 4
#4 0x00000000004308c2 in asn1c_lang_C_type_SEQUENCE (arg=0x7fffffffd280) at asn1c_C.c:386
386 EMBED_WITH_IOCT(v, ioc_tao);
(gdb) p *v
$4 = {
Identifier = 0x69c020 "other-mechanism-name",
meta_type = AMT_TYPEREF,
expr_type = A1TC_REFERENCE,
reference = 0x69c080,
constraints = 0x69c3f0,
combined_constraints = 0x6a2d80,
lhs_params = 0x0,
rhs_pspecs = 0x0,
specializations = {
pspec = 0x0,
pspecs_count = 0
},
spec_index = -1,
value = 0x0,
with_syntax = 0x0,
ioc_table = 0x0,
tag = {
tag_class = TC_NOCLASS,
tag_mode = TM_DEFAULT,
tag_value = 0
},
marker = {
flags = EM_NOMARK,
default_value = 0x0
},
unique = 0,
ref_cnt = 0,
auto_tags_OK = 0,
members = {
tq_head = 0x0,
tq_tail = 0x69c1d0
},
next = {
tq_next = 0x69c670
},
parent_expr = 0x69c480,
module = 0x68d5c0,
_lineno = 212,
---Type <return> to continue, or q <return> to quit---
_mark = TM_NOMARK,
_anonymous_type = 0,
_type_unique_index = 6,
_type_referenced = 0,
data = 0x0,
data_free = 0x0
}
Hi @velichkov, Thank you very much! I changed the defintion and it worked, but then there are some problems with compile of generated code, do you have any idea?
[ 15%] Building C object src/inspectors/dpx/CMakeFiles/dpx.dir/src/acse/ANY.c.o /root/snort_src/snort3_extra/src/inspectors/dpx/src/acse/ANY.c:34:2: error: ‘ANY_decode_aper’ undeclared here (not in a function); did you mean ‘ANY_decode_uper’? ANY_decode_aper, ^
~~~~~~ ANY_decode_uper /root/snort_src/snort3_extra/src/inspectors/dpx/src/acse/ANY.c:35:2: error: ‘ANY_encode_aper’ undeclared here (not in a function); did you mean ‘ANY_encode_uper’? ANY_encode_aper, ^~~~~~~ ANY_encode_uper /root/snort_src/snort3_extra/src/inspectors/dpx/src/acse/ANY.c:37:2: warning: excess elements in struct initializer 0, / Random fill is not defined for ANY type / ^ /root/snort_src/snort3_extra/src/inspectors/dpx/src/acse/ANY.c:37:2: note: (near initialization for ‘asn_OP_ANY’) /root/snort_src/snort3_extra/src/inspectors/dpx/src/acse/ANY.c:38:2: warning: excess elements in struct initializer 0 / Use generic outmost tag fetcher / ^ /root/snort_src/snort3_extra/src/inspectors/dpx/src/acse/ANY.c:38:2: note: (near initialization for ‘asn_OP_ANY’) /root/snort_src/snort3_extra/src/inspectors/dpx/src/acse/ANY.c: In function ‘ANY_fromType_aper’: /root/snort_src/snort3_extra/src/inspectors/dpx/src/acse/ANY.c:131:10: warning: implicit declaration of function ‘aper_encode_to_new_buffer’; did you mean ‘uper_encode_to_new_buffer’? [-Wimplicit-function-declaration] erval = aper_encode_to_new_buffer(td, td->encoding_constraints.per_constraints, sptr, (void)&buffer); ^~~~~~~~~ uper_encode_to_new_buffer /root/snort_src/snort3_extra/src/inspectors/dpx/src/acse/ANY.c: In function ‘ANY_to_type_aper’: /root/snort_src/snort3_extra/src/inspectors/dpx/src/acse/ANY.c:237:9: warning: implicit declaration of function ‘aper_decode’; did you mean ‘uper_decode’? [-Wimplicit-function-declaration] rval = aper_decode(0, td, (void )&newst, st->buf, st->size, 0, 0); ^~~uper_decode /root/snort_src/snort3_extra/src/inspectors/dpx/src/acse/ANY.c:237:7: error: incompatible types when assigning to type ‘asn_dec_rval_t’ {aka ‘struct asn_dec_rval_s’} from type ‘int’ rval = aper_decode(0, td, (void )&newst, st->buf, st->size, 0, 0); ^ /root/snort_src/snort3_extra/src/inspectors/dpx/src/acse/ANY.c: In function ‘ANY_decode_aper’: /root/snort_src/snort3_extra/src/inspectors/dpx/src/acse/ANY.c:393:19: warning: implicit declaration of function ‘aper_get_length’; did you mean ‘uper_get_length’? [-Wimplicit-function-declaration] raw_len = aper_get_length(pd, -1, 0, &repeat); ^~~~~~~ uper_get_length make[2]: ** [src/inspectors/dpx/CMakeFiles/dpx.dir/build.make:219: src/inspectors/dpx/CMakeFiles/dpx.dir/src/acse/ANY.c.o] Error 1 make[1]: [CMakeFiles/Makefile2:932: src/inspectors/dpx/CMakeFiles/dpx.dir/all] Error 2 make: *** [Makefile:152: all] Error 2
/root/snort_src/snort3_extra/src/inspectors/dpx/src/acse/ANY.c:34:2: error: ‘ANY_decode_aper’ undeclared here (not in a function); did you mean ‘ANY_decode_uper’?
Which asn1c
version do you use, could you give me the git commit id?
In 86b05417584ac3f2b820bdd5719516ba2039086e ANY_decode_uper
is declared here
https://github.com/mouse07410/asn1c/blob/86b05417584ac3f2b820bdd5719516ba2039086e/skeletons/ANY.h#L32 used here https://github.com/mouse07410/asn1c/blob/86b05417584ac3f2b820bdd5719516ba2039086e/skeletons/ANY.c#L34
and implemented here
Make sure you don't have multiple versions of ANY.h
. Run make VERBOSE=1
and upload the full log somewhere and provide a link (do not paste it inline as this makes the discussion difficult to follow)
With one more modification I'm able to compile the example
--- ACSE.orig.txt 2019-03-27 15:14:53.517164080 +0200
+++ ACSE.txt 2019-03-27 17:10:56.484588430 +0200
@@ -208,11 +208,8 @@
bitstring [1] IMPLICIT BIT STRING,
external [2] IMPLICIT EXTERNAL,
other
- [3] IMPLICIT SEQUENCE {other-mechanism-name
- MECHANISM-NAME.&id({ObjectSet}),
- other-mechanism-value
- MECHANISM-NAME.&Type
- ({ObjectSet}{@.other-mechanism-name})}
+ [3] IMPLICIT SEQUENCE {other-mechanism-name INTEGER,
+ other-mechanism-value ANY}
}
-- The abstract syntax of (calling/responding) authentication-value is determined by the authentication
@@ -227,10 +224,10 @@
Mechanism-name ::= OBJECT IDENTIFIER
-MECHANISM-NAME ::= TYPE-IDENTIFIER
-
-ObjectSet MECHANISM-NAME ::=
- {...}
+-- MECHANISM-NAME ::= TYPE-IDENTIFIER
+--
+-- ObjectSet MECHANISM-NAME ::=
+-- {...}
Release-request-reason ::= INTEGER {normal(0), urgent(1), user-defined(30)
}(0 | 1 | 30, ...)
asn1c -fcompound-names ACSE.txt
make -f converter-example.mk all
./converter-example --help
I don't know which encoding is used in ACSE but if it's not APER/UPER/OEAR you could try compiling with asn1c -fcompound-names -no-gen-PER -no-gen-OER ACSE.txt
Hi @velichkov ,
You're right, the problem is that I have another version of ANY.h which is created by different version of asn1c from https://github.com/vlm/asn1c. Then I deleted it and problem solved! Thank you again for solving the problem!
Hi @ljy5490,
Better redefine other-mechanism-name
to be OBJECT IDENTIFIER
as other-mechanism-name
have to be equal to mechanism-name
and it's defined to be OBJECT IDENTIFIER
--- ACSE.orig.txt 2019-03-27 15:14:53.517164080 +0200
+++ ACSE.txt 2019-03-27 20:26:08.004110020 +0200
@@ -208,11 +208,8 @@
bitstring [1] IMPLICIT BIT STRING,
external [2] IMPLICIT EXTERNAL,
other
- [3] IMPLICIT SEQUENCE {other-mechanism-name
- MECHANISM-NAME.&id({ObjectSet}),
- other-mechanism-value
- MECHANISM-NAME.&Type
- ({ObjectSet}{@.other-mechanism-name})}
+ [3] IMPLICIT SEQUENCE {other-mechanism-name OBJECT IDENTIFIER,
+ other-mechanism-value ANY}
}
-- ITU-T Rec. X.680 | ISO/IEC 8824. If the value "mechanism-name" occurs in the AARQ-apdu or the -- AARE-apdu, then that value must be the same as the value for "other-mechanism-name"
Mechanism-name ::= OBJECT IDENTIFIER
Hi @velichkov ,
Thank you for the advice! I will change it to the OBJECT IDENTIFIER
And here is another more elegant workaround without removing the information object class and set definitions
diff -u ACSE.orig.txt ACSE.txt
--- ACSE.orig.txt 2019-03-27 15:14:53.517164080 +0200
+++ ACSE.txt 2019-03-28 12:21:57.143075336 +0200
@@ -207,13 +207,14 @@
charstring [0] IMPLICIT GraphicString,
bitstring [1] IMPLICIT BIT STRING,
external [2] IMPLICIT EXTERNAL,
- other
- [3] IMPLICIT SEQUENCE {other-mechanism-name
- MECHANISM-NAME.&id({ObjectSet}),
+ other [3] IMPLICIT Other
+}
+
+Other ::= SEQUENCE {other-mechanism-name
+ TYPE-IDENTIFIER.&id({ObjectSet}),
other-mechanism-value
- MECHANISM-NAME.&Type
+ TYPE-IDENTIFIER.&Type
({ObjectSet}{@.other-mechanism-name})}
-}
-- The abstract syntax of (calling/responding) authentication-value is determined by the authentication
-- mechanism used during association establishment. The authentication mechanism is either explicitly
@@ -227,9 +228,9 @@
Mechanism-name ::= OBJECT IDENTIFIER
-MECHANISM-NAME ::= TYPE-IDENTIFIER
+-- MECHANISM-NAME ::= TYPE-IDENTIFIER
-ObjectSet MECHANISM-NAME ::=
+ObjectSet TYPE-IDENTIFIER ::=
{...}
Release-request-reason ::= INTEGER {normal(0), urgent(1), user-defined(30)
The original ACSE ASN.1 reproduce two problems
TYPE-IDENTIFIER
is a CLASS
defined in skeletons/standard-modules/ASN1C-UsefulInformationObjectClasses.asn1
and MECHANISM-NAME ::= TYPE-IDENTIFIER
result in an error.
Minimal
DEFINITIONS ::=
BEGIN
T ::= SEQUENCE { value SEQUENCE { other-mechanism-name TYPE-IDENTIFIER.&id({ObjectSet}), other-mechanism-value TYPE-IDENTIFIER.&Type({ObjectSet}{@.other-mechanism-name}) } }
ObjectSet TYPE-IDENTIFIER ::= {...}
END
and with equivalent change applied to it that fix the crash.
```asn1
Minimal
DEFINITIONS ::=
BEGIN
T ::= SEQUENCE {
value Value
}
Value ::= SEQUENCE {
other-mechanism-name TYPE-IDENTIFIER.&id({ObjectSet}),
other-mechanism-value TYPE-IDENTIFIER.&Type({ObjectSet}{@.other-mechanism-name})
}
ObjectSet TYPE-IDENTIFIER ::= {...}
END
Hi @velichkov
Really appreciate for the workaround! I didn't go that far in the end, but thank you very much for your effort.
Hi,
I am trying to use asn1c for ACSE-1, but the generation failed with following information: WARNING: GraphicString is not fully supported WARNING: GraphicString is not fully supported asn1c: asn1c_C.c:386: asn1c_lang_C_type_SEQUENCE: Assertion `arg->target->target == OT_TYPE_DECLS || arg->target->target == OT_FWD_DEFS' failed. Aborted (core dumped)
Thank you for your help!