net: ieee802154: Fix dereference before NULL check
Fixes dereference of sec_ctx->level before checking sec_ctx for NULL.
@@ -115,13 +115,15 @@ bool ieee802154_decrypt_auth(struct ieee802154_security_ctx *sec_ctx, uint8_t *f
struct cipher_aead_pkt apkt;
struct cipher_pkt pkt;
uint8_t nonce[13];
- uint8_t level = sec_ctx->level;
+ uint8_t level;
int ret;
- if (!sec_ctx || level == IEEE802154_SECURITY_LEVEL_NONE) {
+ if (!sec_ctx || sec_ctx->level == IEEE802154_SECURITY_LEVEL_NONE) {
return true;
}
+ level = sec_ctx->level;
+
if (level == IEEE802154_SECURITY_LEVEL_ENC) {
/* See comment in ieee802154_encrypt_auth(). */
NET_ERR("Encrypt-only operation is not supported.");
@@ -152,13 +154,15 @@ bool ieee802154_encrypt_auth(struct ieee802154_security_ctx *sec_ctx, uint8_t *f
struct cipher_aead_pkt apkt;
struct cipher_pkt pkt;
uint8_t nonce[13];
- uint8_t level = sec_ctx->level;
+ uint8_t level;
int ret;
- if (!sec_ctx || level == IEEE802154_SECURITY_LEVEL_NONE) {
+ if (!sec_ctx || sec_ctx->level == IEEE802154_SECURITY_LEVEL_NONE) {
return true;
}
+ level = sec_ctx->level;
+
if (level == IEEE802154_SECURITY_LEVEL_ENC) {
/* TODO: We currently use CCM rather than CCM* as crypto.h does
* not provide access to CCM* as of now.
