Skip to content

Commit 61cc05a

Browse files
author
Alain Volmat
committed
display: stm32-ltdc: ensure read/write rectangle fit into display
Ensure that x,y/width-height rectangle mentioned in display_read and display_write are actually part of the framebuffer, otherwise return an error. Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
1 parent 639b04f commit 61cc05a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

drivers/display/display_stm32_ltdc.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,12 @@ static int stm32_ltdc_write(const struct device *dev, const uint16_t x,
181181
const uint8_t *src = buf;
182182
uint16_t row;
183183

184+
/* Validate the given parameters */
185+
if (x + desc->width > config->width || y + desc->height > config->height) {
186+
LOG_ERR("Rectangle does not fit into the display");
187+
return -EINVAL;
188+
}
189+
184190
if ((x == 0) && (y == 0) &&
185191
(desc->width == config->width) &&
186192
(desc->height == config->height) &&
@@ -249,6 +255,12 @@ static int stm32_ltdc_read(const struct device *dev, const uint16_t x,
249255
const uint8_t *src = data->front_buf;
250256
uint16_t row;
251257

258+
/* Validate the given parameters */
259+
if (x + desc->width > config->width || y + desc->height > config->height) {
260+
LOG_ERR("Rectangle does not fit into the display");
261+
return -EINVAL;
262+
}
263+
252264
/* src = pointer to upper left pixel of the rectangle to be read from frame buffer */
253265
src += (x * data->current_pixel_size);
254266
src += (y * config->width * data->current_pixel_size);

0 commit comments

Comments
 (0)