sensor_shell: crash when sensor get <sensor> current
#72838
Labels
area: Sensors
Sensors
bug
The issue is a bug, or the PR is fixing a bug
priority: medium
Medium impact/importance bug
Describe the bug
Currently, getting any channel >=
SENSOR_CHAN_VSHUNT
would result in a crash:This is because the
SENSOR_CHAN_VSHUNT
was added in #60717 but was never added to thesensor_channel_name[SENSOR_CHAN_COMMON_COUNT]
table. Since the length ofsensor_channel_name
is fixed toSENSOR_CHAN_COMMON_COUNT
, this means that the index atSENSOR_CHAN_VSHUNT
points toNULL
. When we use thesensor get
command for anything bigger thanSENSOR_CHAN_VSHUNT
, we will deref thatNULL
pointer when we dostrcmp
in the for-loop ofparse_named_int
:zephyr/drivers/sensor/sensor_shell.c
Lines 246 to 250 in 4efc035
To Reproduce
Steps to reproduce the behavior:
sensor_shell
sensor with board that has a sensor, or check-out samples: sensor_shell: add fake sensor driver & pytest #72833sensor get <sensor node> voltage
-> oksensor get <sensor node> current
-> crashExpected behavior
User should be able to
get
any channel without crashing the applicationImpact
sensor get
command won't be able to get anything further thanvoltage
, passing number as the arg works though:Logs and console output
See above
Environment (please complete the following information):
The text was updated successfully, but these errors were encountered: