From 902531bd817b46a80d78ee036f0f447d6f080467 Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Wed, 20 Oct 2021 17:22:58 +0200 Subject: csn1: Avoid storing existence bit as true if content was actually NULL If we decode Exist bit as "1" but we are at the end of the message, and all the Next items we'd read are expected to be possibly NULL, then swap the Exist bit in the decoded structure as "0" in order to tell the decoder user that the related information structure is actually unset, as if "0" was received. This patch is a port from patch fixing same issue in the osmo-pcu.git copy of csn1 decoder: https://git.osmocom.org/osmo-pcu/commit/?id=1859ec38cc4f4e3788e495a100fdec3787d25020 And fixup patch for that one: https://git.osmocom.org/osmo-pcu/commit/?id=9ecdc11eb6b983748ae2fd6a1d07849c8106826f --- epan/dissectors/packet-csn1.c | 45 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/epan/dissectors/packet-csn1.c b/epan/dissectors/packet-csn1.c index b54b672a5f..ddba95211c 100644 --- a/epan/dissectors/packet-csn1.c +++ b/epan/dissectors/packet-csn1.c @@ -1070,7 +1070,7 @@ csnStreamDissector(proto_tree *tree, csnStream_t* ar, const CSN_DESCR* pDescr, t case CSN_NEXT_EXIST: { - guint8 fExist; + guint8 isnull; pui8 = pui8DATA(data, pDescr->offset); @@ -1089,18 +1089,30 @@ csnStreamDissector(proto_tree *tree, csnStream_t* ar, const CSN_DESCR* pDescr, t /* the "regular" M_NEXT_EXIST description element */ proto_tree_add_bits_item(tree, *(pDescr->hf_ptr), tvb, bit_offset, 1, ENC_BIG_ENDIAN); - fExist = 0x00; + isnull = 1; if (tvb_get_bits8(tvb, bit_offset, 1)) { - fExist = 0x01; + if (remaining_bits_len == 1) + { + /* If { 1 < end > } and all next items may be null, store it as { 0 } */ + const CSN_DESCR* pDescrNext = pDescr + 1; + guint8 i; + for (i = 0; i < pDescr->i; i++, pDescrNext++) + { + if (!pDescrNext->may_be_null) + isnull = 0; + } + } else { + isnull = 0; + } } - *pui8 = fExist; + *pui8 = !isnull; remaining_bits_len --; bit_offset++; - if (fExist == 0) + if (isnull) { /* Skip 'i' entries */ pDescr += pDescr->i; } @@ -1111,7 +1123,7 @@ csnStreamDissector(proto_tree *tree, csnStream_t* ar, const CSN_DESCR* pDescr, t case CSN_NEXT_EXIST_LH: { - guint8 fExist; + guint8 isnull; pui8 = pui8DATA(data, pDescr->offset); /* this if-statement represents the M_NEXT_EXIST_OR_NULL_LH description element */ @@ -1129,14 +1141,29 @@ csnStreamDissector(proto_tree *tree, csnStream_t* ar, const CSN_DESCR* pDescr, t /* the "regular" M_NEXT_EXIST_LH description element */ proto_tree_add_bits_item(tree, *(pDescr->hf_ptr), tvb, bit_offset, 1, ENC_BIG_ENDIAN); - fExist = tvb_get_masked_bits8(tvb, bit_offset, 1); + isnull = 1; + if (tvb_get_masked_bits8(tvb, bit_offset, 1)) + { + if (remaining_bits_len == 1) { + /* If { 1 < end > } and all next items may be null, store it as { 0 } */ + const CSN_DESCR* pDescrNext = pDescr + 1; + guint8 i; + for (i = 0; i < pDescr->i; i++, pDescrNext++) + { + if (!pDescrNext->may_be_null) + isnull = 0; + } + } else { + isnull = 0; + } + } - *pui8++ = fExist; + *pui8++ = !isnull; remaining_bits_len --; bit_offset++; - if (fExist == 0) + if (isnull) { /* Skip 'i' entries */ pDescr += pDescr->i; } -- cgit v1.2.3