From 93ad3fd9b9aed26a609551c06a80db0e276eb4f1 Mon Sep 17 00:00:00 2001 From: Vadim Yanitskiy Date: Sat, 23 May 2020 18:17:19 +0700 Subject: csn1: fix: never use enumerated types in codec structures I faced a problem while working on EGPRS Packet Channel Request coding support: the unit test I wrote for it was passing when compiled with AddressSanitizer, but failing when compiled without it o_O. Somehow this was observed only with GCC 10. Here is a part the standard output diff for that unit test: *** testEGPRSPktChReq *** decode_egprs_pkt_ch_req(0x2b5) returns 0 - ==> One Phase Access + ==> unknown 0xdd5f4e00 decode_egprs_pkt_ch_req(0x14a) returns 0 - ==> One Phase Access + ==> unknown 0xdd5f4e00 decode_egprs_pkt_ch_req(0x428) returns 0 - ==> Short Access + ==> unknown 0xdd5f4e01 At the same time, debug output of the CSN.1 decoder looked fine. So WYSINWYG (What You See Is *NOT* What You Get)! As it turned out, this was happening because I used an enumerated type to represent the sub-type of EGPRS Packet Channel Request. typedef struct { EGPRS_PacketChannelRequestType_t Type; // <-- enum EGPRS_PacketChannelRequestContent_t Content; } EGPRS_PacketChannelRequest_t; The problem is that length of an enumerated field, more precisely the amount of bytes it takes in the memory, is compiler/machine dependent. While the CSN.1 decoder assumes that the field holding sequential number of the chosen element is one octet long, so its address is getting casted to (guint8 *) and the value is written to the first MSB. // csnStreamDecoder(), case CSN_CHOICE: pui8 = pui8DATA(data, pDescr->offset); *pui8 = i; // [ --> xx .. .. .. ] Let's make sure that none of the existing RLC/MAC definitions is using enumerated types, and add a warning comment to CSN_CHOICE. Affected CSN.1 definitions (unit test output adjusted): - Additional_access_technologies_struct_t, - Channel_Request_Description_t. Change-Id: I917a40647480c6f6f3b0e68674ce9894379a9e7f --- src/gsm_rlcmac.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/gsm_rlcmac.h') diff --git a/src/gsm_rlcmac.h b/src/gsm_rlcmac.h index e9ae20ae..9d859f33 100644 --- a/src/gsm_rlcmac.h +++ b/src/gsm_rlcmac.h @@ -158,7 +158,7 @@ typedef struct { guint8 PEAK_THROUGHPUT_CLASS; guint8 RADIO_PRIORITY; - RLC_MODE_t RLC_MODE; + guint8 RLC_MODE; guint8 LLC_PDU_TYPE; guint16 RLC_OCTET_COUNT; } Channel_Request_Description_t; @@ -1245,7 +1245,7 @@ typedef enum typedef struct { - AccessTechnology_t Access_Technology_Type; + guint8 Access_Technology_Type; guint8 GMSK_Power_class; guint8 Eight_PSK_Power_class; } Additional_access_technologies_struct_t; -- cgit v1.2.3