Skip to content

Commit 14aba71

Browse files
author
Tomasz Bursztyka
committed
net/ieee802154: Invalidate frame in case of no address in relevant modes
All addressing mode but IEEE802154_ADDR_MODE_NONE should have a valid address. If not, the frame is invalid. Signed-off-by: Tomasz Bursztyka <[email protected]>
1 parent b492926 commit 14aba71

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

subsys/net/l2/ieee802154/ieee802154_frame.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ struct ieee802154_fcf_seq *ieee802154_validate_fc_seq(uint8_t *buf, uint8_t **p_
8989
return fs;
9090
}
9191

92-
static inline struct ieee802154_address_field *
93-
validate_addr(uint8_t *buf, uint8_t **p_buf, uint8_t *length,
94-
enum ieee802154_addressing_mode mode,
95-
bool pan_id_compression)
92+
static inline bool validate_addr(uint8_t *buf, uint8_t **p_buf, uint8_t *length,
93+
enum ieee802154_addressing_mode mode,
94+
bool pan_id_compression,
95+
struct ieee802154_address_field **addr)
9696
{
9797
uint8_t len = 0;
9898

@@ -102,7 +102,8 @@ validate_addr(uint8_t *buf, uint8_t **p_buf, uint8_t *length,
102102
buf, mode, pan_id_compression);
103103

104104
if (mode == IEEE802154_ADDR_MODE_NONE) {
105-
return NULL;
105+
*addr = NULL;
106+
return true;
106107
}
107108

108109
if (!pan_id_compression) {
@@ -117,13 +118,15 @@ validate_addr(uint8_t *buf, uint8_t **p_buf, uint8_t *length,
117118
}
118119

119120
if (len > *length) {
120-
return NULL;
121+
return false;
121122
}
122123

123124
*p_buf += len;
124125
*length -= len;
125126

126-
return (struct ieee802154_address_field *)buf;
127+
*addr = (struct ieee802154_address_field *)buf;
128+
129+
return true;
127130
}
128131

129132
#ifdef CONFIG_NET_L2_IEEE802154_SECURITY
@@ -439,13 +442,15 @@ bool ieee802154_validate_frame(uint8_t *buf, uint8_t length,
439442
return false;
440443
}
441444

442-
mpdu->mhr.dst_addr = validate_addr(p_buf, &p_buf, &length,
443-
mpdu->mhr.fs->fc.dst_addr_mode,
444-
false);
445-
446-
mpdu->mhr.src_addr = validate_addr(p_buf, &p_buf, &length,
447-
mpdu->mhr.fs->fc.src_addr_mode,
448-
(mpdu->mhr.fs->fc.pan_id_comp));
445+
if (!validate_addr(p_buf, &p_buf, &length,
446+
mpdu->mhr.fs->fc.dst_addr_mode,
447+
false, &mpdu->mhr.dst_addr) ||
448+
!validate_addr(p_buf, &p_buf, &length,
449+
mpdu->mhr.fs->fc.src_addr_mode,
450+
(mpdu->mhr.fs->fc.pan_id_comp),
451+
&mpdu->mhr.src_addr)) {
452+
return false;
453+
}
449454

450455
#ifdef CONFIG_NET_L2_IEEE802154_SECURITY
451456
if (mpdu->mhr.fs->fc.security_enabled) {

0 commit comments

Comments
 (0)