From beb7c1741ee8f39a96d5fab6845f415b232d5fb4 Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Fri, 28 Apr 2023 17:33:36 +0200 Subject: [PATCH] Fix 'Fix parsing of TLV_TYPE_SINGLE_TV' A commit was merged recently attempting to fix decoding of TLV_TYPE_SINGLE_TV. It did mostly a good job, but missed updating the o_tag pointer used to fill in the structures. This commit fixes that specific part missing. Fixes: 559a6ee68359dab691a483573982e6f8c6439ae2 Change-Id: Id619459c17976b77cd2c7e4179123bb06807285c --- src/gsm/tlv_parser.c | 14 +++++++++++--- tests/tlv/tlv_test.c | 6 ++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/gsm/tlv_parser.c b/src/gsm/tlv_parser.c index e47b94f11..8dd460db5 100644 --- a/src/gsm/tlv_parser.c +++ b/src/gsm/tlv_parser.c @@ -225,7 +225,11 @@ int tlv_encode_ordered(struct msgb *msg, const struct tlv_definition *def, const * \param[in] def structure defining the valid TLV tags / configurations * \param[in] buf the input data buffer to be parsed * \param[in] buf_len length of the input data buffer - * \returns number of bytes consumed by the TLV entry / IE parsed; negative in case of error + * \returns number of bytes consumed by the TLV entry / IE parsed; negative in case of error. + * + * In IEs of type TLV_TYPE_SINGLE_TV, the data pointer \ref o_val will point to the + * byte shared by both the Tag and te Value, hence the tag is to be trimmed + * by the caller. */ int tlv_parse_one(uint8_t *o_tag, uint16_t *o_len, const uint8_t **o_val, const struct tlv_definition *def, @@ -241,9 +245,13 @@ int tlv_parse_one(uint8_t *o_tag, uint16_t *o_len, const uint8_t **o_val, *o_tag = tag; /* single octet TV IE */ - if (def->def[tag >> 4].type == TLV_TYPE_SINGLE_TV + if (def->def[tag >> 4].type == TLV_TYPE_SINGLE_TV) { + *o_tag = tag >> 4; + *o_val = buf; + *o_len = 1; + return 1; + } else if ((tag > 0x0f) && (def->def[tag & 0xf0].type == TLV_TYPE_SINGLE_TV)) { /* backward compat for old IEs with half-octet tag defined as 0xN0: */ - || ((tag > 0x0f) && (def->def[tag & 0xf0].type == TLV_TYPE_SINGLE_TV))) { *o_tag = tag & 0xf0; *o_val = buf; *o_len = 1; diff --git a/tests/tlv/tlv_test.c b/tests/tlv/tlv_test.c index aaa86a3ac..8e8bd603f 100644 --- a/tests/tlv/tlv_test.c +++ b/tests/tlv/tlv_test.c @@ -470,14 +470,12 @@ static void test_tlv_type_single_tv(void) rc = tlv_parse(&tp, &att_tlvdef, buf, sizeof(buf), 0, 0); OSMO_ASSERT(rc == 1); - OSMO_ASSERT(!TLVP_PRESENT(&tp, SAMPLE_SINGLE_TV_IE)); //FIXME! + OSMO_ASSERT(TLVP_PRESENT(&tp, SAMPLE_SINGLE_TV_IE)); val = TLVP_VAL(&tp, SAMPLE_SINGLE_TV_IE); - OSMO_ASSERT(!val); //FIXME! -#if 0 + OSMO_ASSERT(val); OSMO_ASSERT(val == &buf[0]); OSMO_ASSERT(*val == buf[0]); OSMO_ASSERT((*val & 0x0f) == exp_val); -#endif } int main(int argc, char **argv)