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 { ...@@ -107,12 +107,13 @@ typedef struct {
uint8_t R: 2; // octet 1 [7:6] uint8_t R: 2; // octet 1 [7:6]
} __attribute__ ((__packed__)) NR_MAC_SUBHEADER_FIXED; } __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) { 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 < (int)sizeof(NR_MAC_SUBHEADER_SHORT)) {
if (pdu_len < sizeof(NR_MAC_SUBHEADER_SHORT))
return false; return false;
NR_MAC_SUBHEADER_SHORT *s = (NR_MAC_SUBHEADER_SHORT*) pdu; NR_MAC_SUBHEADER_SHORT *s = (NR_MAC_SUBHEADER_SHORT *)pdu;
NR_MAC_SUBHEADER_LONG *l = (NR_MAC_SUBHEADER_LONG*) pdu; NR_MAC_SUBHEADER_LONG *l = (NR_MAC_SUBHEADER_LONG *)pdu;
if (s->F && pdu_len < (int)sizeof(NR_MAC_SUBHEADER_LONG)) if (s->F && pdu_len < sizeof(NR_MAC_SUBHEADER_LONG))
return false; return false;
if (s->F) { if (s->F) {
*mac_subheader_len = sizeof(*l); *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 ...@@ -123,7 +124,7 @@ static inline int get_mac_len(uint8_t* pdu, int pdu_len, uint16_t *mac_ce_len, u
} }
return true; return true;
} }
// BSR MAC CEs // BSR MAC CEs
// TS 38.321 ch. 6.1.3.1 // TS 38.321 ch. 6.1.3.1
// Short BSR for a specific logical channel group ID // 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) ...@@ -55,7 +55,13 @@ static rnti_t lcid_crnti_lookahead(uint8_t *pdu, uint32_t pdu_len)
break; break;
} }
pdu += mac_len + mac_subheader_len; 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; 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