Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sensor_shell: crash when sensor get <sensor> current #72838

Closed
ycsin opened this issue May 16, 2024 · 0 comments · Fixed by #72815
Closed

sensor_shell: crash when sensor get <sensor> current #72838

ycsin opened this issue May 16, 2024 · 0 comments · Fixed by #72815
Assignees
Labels
area: Sensors Sensors bug The issue is a bug, or the PR is fixing a bug priority: medium Medium impact/importance bug

Comments

@ycsin
Copy link
Collaborator

ycsin commented May 16, 2024

Describe the bug
Currently, getting any channel >= SENSOR_CHAN_VSHUNT would result in a crash:

uart:~$ sensor get sensor@0 current
[870:26:48.134,000] <err> os: 
[870:26:48.134,000] <err> os:  mcause: 5, Load access fault
[870:26:48.134,000] <err> os:   mtval: 0
[870:26:48.134,000] <err> os:      a0: 0000000080016b36    t0: 000000008000dfc0
[870:26:48.134,000] <err> os:      a1: 0000000000000000    t1: 0000000000000039
[870:26:48.134,000] <err> os:      a2: 0000000000000063    t2: 0000000000000000
[870:26:48.134,000] <err> os:      a3: 0000000000000076    t3: 000000000000000c
[870:26:48.134,000] <err> os:      a4: 0000000080016b37    t4: 0000000000000020
[870:26:48.134,000] <err> os:      a5: 0000000000000063    t5: aaaaaaaaaaaaaaaa
[870:26:48.134,000] <err> os:      a6: 000000000000000a    t6: aaaaaaaaaaaaaaaa
[870:26:48.134,000] <err> os:      a7: 0000000080016b36
[870:26:48.134,000] <err> os:      sp: 0000000080019870
[870:26:48.134,000] <err> os:      ra: 0000000080008b86
[870:26:48.134,000] <err> os:    mepc: 000000008000ddd2
[870:26:48.134,000] <err> os: mstatus: 0000000a00001880
[870:26:48.134,000] <err> os: 
[870:26:48.134,000] <err> os: >>> ZEPHYR FATAL ERROR 0: CPU exception on CPU 0
[870:26:48.134,000] <err> os: Current thread: 0x80016688 (shell_uart)
[870:26:48.144,000] <err> os: Halting system

This is because the SENSOR_CHAN_VSHUNT was added in #60717 but was never added to the sensor_channel_name[SENSOR_CHAN_COMMON_COUNT] table. Since the length of sensor_channel_name is fixed to SENSOR_CHAN_COMMON_COUNT, this means that the index at SENSOR_CHAN_VSHUNT points to NULL. When we use the sensor get command for anything bigger than SENSOR_CHAN_VSHUNT, we will deref that NULL pointer when we do strcmp in the for-loop of parse_named_int:

for (i = 0; i < count; i++) {
if (strcmp(name, heystack[i]) == 0) {
return i;
}
}

To Reproduce
Steps to reproduce the behavior:

  1. Build the sensor_shell sensor with board that has a sensor, or check-out samples: sensor_shell: add fake sensor driver & pytest #72833
  2. sensor get <sensor node> voltage -> ok
  3. sensor get <sensor node> current -> crash

Expected behavior
User should be able to get any channel without crashing the application

Impact
sensor get command won't be able to get anything further than voltage, passing number as the arg works though:

sensor get <sensor node> 32 # 32 is SENSOR_CHAN_VSHUNT

Logs and console output
See above

Environment (please complete the following information):

  • OS: Unix
  • Toolchain: Zephyr SDK 16.5.0-1
  • Latest main
@ycsin ycsin added the bug The issue is a bug, or the PR is fixing a bug label May 16, 2024
@ycsin ycsin added the area: Sensors Sensors label May 16, 2024
@nashif nashif added the priority: medium Medium impact/importance bug label May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Sensors Sensors bug The issue is a bug, or the PR is fixing a bug priority: medium Medium impact/importance bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants