Commit f58765d0 authored by Rúben Soares Silva's avatar Rúben Soares Silva

Update sdu_lenP to uint32_t in get_mac_len

Add check in lcid_crnti_lookahead to ensure subtraction to pdu_len doesn't cause an underflow
parent 22ba6b75
......@@ -107,12 +107,13 @@ typedef struct {
uint8_t R: 2; // octet 1 [7:6]
} __attribute__ ((__packed__)) NR_MAC_SUBHEADER_FIXED;
static inline int get_mac_len(uint8_t* pdu, int pdu_len, uint16_t *mac_ce_len, uint16_t *mac_subheader_len) {
if ( pdu_len < (int)sizeof(NR_MAC_SUBHEADER_SHORT))
static inline int get_mac_len(uint8_t *pdu, uint32_t pdu_len, uint16_t *mac_ce_len, uint16_t *mac_subheader_len)
{
if (pdu_len < sizeof(NR_MAC_SUBHEADER_SHORT))
return false;
NR_MAC_SUBHEADER_SHORT *s = (NR_MAC_SUBHEADER_SHORT*) pdu;
NR_MAC_SUBHEADER_LONG *l = (NR_MAC_SUBHEADER_LONG*) pdu;
if (s->F && pdu_len < (int)sizeof(NR_MAC_SUBHEADER_LONG))
NR_MAC_SUBHEADER_SHORT *s = (NR_MAC_SUBHEADER_SHORT *)pdu;
NR_MAC_SUBHEADER_LONG *l = (NR_MAC_SUBHEADER_LONG *)pdu;
if (s->F && pdu_len < sizeof(NR_MAC_SUBHEADER_LONG))
return false;
if (s->F) {
*mac_subheader_len = sizeof(*l);
......@@ -123,7 +124,7 @@ static inline int get_mac_len(uint8_t* pdu, int pdu_len, uint16_t *mac_ce_len, u
}
return true;
}
// BSR MAC CEs
// TS 38.321 ch. 6.1.3.1
// Short BSR for a specific logical channel group ID
......
......@@ -55,7 +55,13 @@ static rnti_t lcid_crnti_lookahead(uint8_t *pdu, uint32_t pdu_len)
break;
}
pdu += mac_len + mac_subheader_len;
pdu_len -= mac_len + mac_subheader_len;
// if pdu_len can have the value subtracted without underflow, we can subtract
if (pdu_len >= mac_len + mac_subheader_len) {
pdu_len -= mac_len + mac_subheader_len;
} else {
// if not, set to 0 to prevent underflow
pdu_len = 0;
}
}
return 0;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment