From 32c78e331744b8c011ea3b996f293bbf16c3c9dd Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Sun, 8 Mar 2020 17:07:22 +0100 Subject: [PATCH 1/2] gnrc/lorawan: fix netopt_state_t size in link_layer `netopt_state_t` is an enumeration type which is not necessarily 1 byte. If `uint8_t` is used, the cast `*((const netopt_state_t*) val` in `sx127x_netdev::_set`tries to read the real size, which can be more than the given length of 1 byte. Therefore, `netstat_opt_t` has to be used instead of `uint8_t` --- sys/net/gnrc/link_layer/lorawan/gnrc_lorawan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/net/gnrc/link_layer/lorawan/gnrc_lorawan.c b/sys/net/gnrc/link_layer/lorawan/gnrc_lorawan.c index bbfdc51678..db93cfc806 100644 --- a/sys/net/gnrc/link_layer/lorawan/gnrc_lorawan.c +++ b/sys/net/gnrc/link_layer/lorawan/gnrc_lorawan.c @@ -143,7 +143,7 @@ void gnrc_lorawan_open_rx_window(gnrc_lorawan_t *mac) if (mac->state == LORAWAN_STATE_RX_1) { xtimer_set_msg(&mac->rx, _DRIFT_FACTOR, &mac->msg, thread_getpid()); } - uint8_t state = NETOPT_STATE_RX; + netopt_state_t state = NETOPT_STATE_RX; dev->driver->set(dev, NETOPT_STATE, &state, sizeof(state)); } From 3adbbdcf9bbe0d6b6acff941725dcca869f8e58e Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Sun, 8 Mar 2020 17:09:21 +0100 Subject: [PATCH 2/2] drivers/sx127x: fix length check of `netstat_opt_t`in _set --- drivers/sx127x/sx127x_netdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/sx127x/sx127x_netdev.c b/drivers/sx127x/sx127x_netdev.c index cd7ad452f3..470a42f7bd 100644 --- a/drivers/sx127x/sx127x_netdev.c +++ b/drivers/sx127x/sx127x_netdev.c @@ -351,7 +351,7 @@ static int _set(netdev_t *netdev, netopt_t opt, const void *val, size_t len) switch(opt) { case NETOPT_STATE: - assert(len <= sizeof(netopt_state_t)); + assert(len == sizeof(netopt_state_t)); return _set_state(dev, *((const netopt_state_t*) val)); case NETOPT_DEVICE_TYPE: