P1sec / pycrate

A Python library to ease the development of encoders and decoders for various protocols and file formats; contains ASN.1 and CSN.1 compilers.
GNU Lesser General Public License v2.1
380 stars 130 forks source link

Problem with handling "unable to retrieve a table-looked up object" in _from_jval() #238

Closed lubosve closed 1 year ago

lubosve commented 1 year ago

I am observing the problem that is listed below. When I looked into the file, I can't see 'err' defined anywhere. Was it intended to be a reference to 'val', or it should be obtained somewhere?

https://github.com/P1sec/pycrate/blob/d23d526d850fbc77cf54dc3aa158540b22217ee4/pycrate_asn1rt/asnobj_ext.py#L594-L602

    PDU_RANAP.from_jer(json.dumps(ranap_data))
/usr/local/lib/python3.6/site-packages/pycrate_asn1rt/asnobj.py:1968: in from_jer
    self._from_jval(val)
/usr/local/lib/python3.6/site-packages/pycrate_asn1rt/asnobj_construct.py:563: in _from_jval
    self._cont[ident]._from_jval(value)
/usr/local/lib/python3.6/site-packages/pycrate_asn1rt/asnobj_construct.py:1287: in _from_jval
    Comp._from_jval( val[ident] )
/usr/local/lib/python3.6/site-packages/pycrate_asn1rt/asnobj_ext.py:626: in _from_jval
    Obj._from_jval(val)
/usr/local/lib/python3.6/site-packages/pycrate_asn1rt/asnobj_construct.py:1287: in _from_jval
    Comp._from_jval( val[ident] )
/usr/local/lib/python3.6/site-packages/pycrate_asn1rt/asnobj_construct.py:3180: in _from_jval
    self._cont._from_jval(v)
/usr/local/lib/python3.6/site-packages/pycrate_asn1rt/asnobj_construct.py:1287: in _from_jval
    Comp._from_jval( val[ident] )
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <value ([RANAP-PROTOCOL-IES.&Value] OPEN_TYPE)>, val = '000003'

    def _from_jval(self, val):
        # same as PER decodeing
        # try to get a defined object from a table constraint
        if self._TAB_LUT and self._const_tab and self._const_tab_at:
            const_obj_type, const_obj = self._get_tab_obj()
            if const_obj_type == CLASET_NONE:
                if not self._SILENT:
                    asnlog('OPEN._from_jval: %s, unable to retrieve a table-looked up object, %s'\
>                          % (self.fullname(), err))
E                   NameError: name 'err' is not defined
/usr/local/lib/python3.6/site-packages/pycrate_asn1rt/asnobj_ext.py:602: NameError
p1-bmu commented 1 year ago

Looks like the function is missing some statements !

p1-bmu commented 1 year ago

Actually, this one was easy. No missing statement, just an old exception badly converted to a simple log. Fix is https://github.com/P1sec/pycrate/commit/65df070a527fc7df9b7ef8a62c691eaedd9bf6ed