foc_sensor_mode from COMM_SET_MCCONF isn't range-checked, and the FOC ISR switch has no default
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 58/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- c
- Domain
- embedded-iot
Research direction
Read confgenerator.c around the deserialization at line 425, commands_apply_mcconf_hw_limits, and the mcpwm_foc_adc_int_handler switch in motor/mcpwm_foc.c around lines 3473–3618. Trace when the configuration is applied and how invalid sensor modes affect phase updates; then decide where validation belongs and how to handle an invalid value. Done means an out-of-range mode cannot leave rotor angle updates stuck, with coverage for that case.
Written by the indexing model from the issue text.
Description
Hi, I think an out-of-range foc_sensor_mode in a configuration packet makes the FOC interrupt stop updating the rotor angle.
The bug
The deserializer stores the byte as is (confgenerator.c L425):
conf->foc_sensor_mode = buffer[ind++];
The enum has 10 values (FOC_SENSOR_MODE_SENSORLESS … FOC_SENSOR_MODE_ENCODER_AB). The switch in mcpwm_foc_adc_int_handler (mcpwm_foc.c L3473-L3601) has a case for each of them and no default. For a value of 10 or more no case runs, and outside handbrake, open-loop and phase override nothing else assigns state_now->phase (L3603-L3618), so current control keeps driving the last angle.
I couldn't find a range check on the way in: not in confgenerator_deserialize_mcconf and not in commands_apply_mcconf_hw_limits. The switch at L3724 reads the same field.
What it costs
VESC Tool sends valid values, so this needs a buggy tool or a hand-made packet. If it happens, the motor is driven at a frozen angle instead of faulting. This is similar to #930. I found it by reading the code and have not reproduced it on hardware.
Fix
Validate the field when a configuration is applied, for example in commands_apply_mcconf_hw_limits:
if (mcconf->foc_sensor_mode > FOC_SENSOR_MODE_ENCODER_AB) {
mcconf->foc_sensor_mode = FOC_SENSOR_MODE_SENSORLESS;
}
or give the ISR switch a default that raises a fault.
- Dominant language
- C
- Stars
- 3.6k
- Forks
- 2k
- Avg merge
- 20h 29m
- Merged PRs (30d)
- 12
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from vedderb/bldc
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
CAN_PACKET_FILL_RX_BUFFER(_LONG): a frame shorter than its header makes `len` negative before memcpyOpen
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 75/100
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day
-
good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
erkamyaman/rust-anything#1372 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
deprecation:active impact:breaking-change
Difficulty 1/5 1-3 hours Newbie friendliness 80/100
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Cisco-Talos/clamav#1957 ·
Maintainers usually reply within 1 day