-
Notifications
You must be signed in to change notification settings - Fork 0
Add bounds checking for arduino_pins array access in digital_pin_gpios path #6
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,3 @@ | ||
| rust/Cargo.lock | ||
| _codeql_build_dir/ | ||
| _codeql_detected_source_root |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -115,22 +115,25 @@ constexpr inline pin_size_t global_gpio_pin(const struct device *lport, pin_size | |
|
|
||
| constexpr inline const struct device *local_gpio_port(pin_size_t gpin) { | ||
| #if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), digital_pin_gpios) | ||
| return arduino_pins[gpin].port; | ||
| return (gpin < ARRAY_SIZE(arduino_pins)) ? arduino_pins[gpin].port : nullptr; | ||
| #else | ||
| return local_gpio_port_r(gpin, gpio_ports, 0, gpio_ngpios, ARRAY_SIZE(gpio_ports)); | ||
| #endif | ||
| } | ||
|
|
||
| constexpr inline pin_size_t local_gpio_pin(pin_size_t gpin) { | ||
| #if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), digital_pin_gpios) | ||
| return arduino_pins[gpin].pin; | ||
| return (gpin < ARRAY_SIZE(arduino_pins)) ? arduino_pins[gpin].pin : pin_size_t(-1); | ||
| #else | ||
| return port_idx(gpin) == pin_size_t(-1) ? pin_size_t(-1) : gpin - end_accum(port_idx(gpin)); | ||
| #endif | ||
| } | ||
|
|
||
| inline int global_gpio_pin_configure(pin_size_t pinNumber, int flags) { | ||
| #if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), digital_pin_gpios) | ||
| if (pinNumber >= ARRAY_SIZE(arduino_pins)) { | ||
| return -1; | ||
| } | ||
|
Comment on lines
132
to
+136
|
||
| return gpio_pin_configure_dt(&arduino_pins[pinNumber], flags); | ||
| #else | ||
| const struct device *port = local_gpio_port(pinNumber); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
local_gpio_port()now returnsnullptrandlocal_gpio_pin()can returnpin_size_t(-1)for out-of-range pins, but at least one call site (e.g.attachInterrupt()) assumes a valid port/pin: it assertspcb != nullptreven whenportisnullptr, and then doesBIT(local_gpio_pin(pinNumber))which becomes a shift by -1. Please add consistent guards in callers (or in a shared helper) to early-return whenlocal_gpio_port()is null and/orlocal_gpio_pin()is-1before any indexing/bit-shifts/dereferences.