Skip to content

Commit d380d43

Browse files
Alicipykartben
authored andcommitted
drivers: led_strip: ws2812_gpio: prevent overflow
In case one defines an RGB led that is bigger than the led_rgb struct, ws2812_gpio_update_rgb would overflow the buffer it writes to while iterating. This could lead to crashes, as the code would also support GRBW (as supposed in one comment). As a 'proper' fix would require another buffer and therefore more memory, I added a BUILD_ASSERT to ensure it does not compile. Signed-off-by: Stefan Kraus <[email protected]>
1 parent 73eb7bb commit d380d43

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

drivers/led_strip/ws2812_gpio.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ static const uint8_t ws2812_gpio_##idx##_color_mapping[] = \
225225
return gpio_pin_configure_dt(&cfg->gpio, GPIO_OUTPUT); \
226226
} \
227227
\
228+
BUILD_ASSERT(WS2812_NUM_COLORS(idx) <= sizeof(struct led_rgb), \
229+
"Too many channels in color-mapping; " \
230+
"currently not supported by the ws2812_gpio driver"); \
231+
\
228232
WS2812_COLOR_MAPPING(idx); \
229233
\
230234
static const struct ws2812_gpio_cfg ws2812_gpio_##idx##_cfg = { \

0 commit comments

Comments
 (0)