* [PATCH] driver: video: Check allocated pointers
@ 2022-05-18 5:36 Bin Meng
2022-06-25 7:10 ` Anatolij Gustschin
0 siblings, 1 reply; 2+ messages in thread
From: Bin Meng @ 2022-05-18 5:36 UTC (permalink / raw)
To: Anatolij Gustschin, u-boot
The codes that call STBTT_malloc() / stbtt__new_active() do not check
the return value at present which may cause segfault.
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
---
drivers/video/stb_truetype.h | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/drivers/video/stb_truetype.h b/drivers/video/stb_truetype.h
index 26f4ac2ca8..438bfce468 100644
--- a/drivers/video/stb_truetype.h
+++ b/drivers/video/stb_truetype.h
@@ -1768,10 +1768,13 @@ static void stbtt__rasterize_sorted_edges(stbtt__bitmap *result, stbtt__edge *e,
int s; // vertical subsample index
unsigned char scanline_data[512], *scanline;
- if (result->w > 512)
+ if (result->w > 512) {
scanline = (unsigned char *) STBTT_malloc(result->w, userdata);
- else
+ if (!scanline)
+ return;
+ } else {
scanline = scanline_data;
+ }
y = off_y * vsubsample;
e[n].y0 = (off_y + result->h) * (float) vsubsample + 1;
@@ -1821,6 +1824,8 @@ static void stbtt__rasterize_sorted_edges(stbtt__bitmap *result, stbtt__edge *e,
while (e->y0 <= scan_y) {
if (e->y1 > scan_y) {
stbtt__active_edge *z = stbtt__new_active(&hh, e, off_x, scan_y, userdata);
+ if (!z)
+ return;
// find insertion point
if (active == NULL)
active = z;
@@ -2068,10 +2073,13 @@ static void stbtt__rasterize_sorted_edges(stbtt__bitmap *result, stbtt__edge *e,
int y,j=0, i;
float scanline_data[129], *scanline, *scanline2;
- if (result->w > 64)
+ if (result->w > 64) {
scanline = (float *) STBTT_malloc((result->w*2+1) * sizeof(float), userdata);
- else
+ if (!scanline)
+ return;
+ } else {
scanline = scanline_data;
+ }
scanline2 = scanline + result->w;
@@ -2105,6 +2113,8 @@ static void stbtt__rasterize_sorted_edges(stbtt__bitmap *result, stbtt__edge *e,
while (e->y0 <= scan_y_bottom) {
if (e->y0 != e->y1) {
stbtt__active_edge *z = stbtt__new_active(&hh, e, off_x, scan_y_top, userdata);
+ if (!z)
+ return;
STBTT_assert(z->ey >= scan_y_top);
// insert at front
z->next = active;
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] driver: video: Check allocated pointers
2022-05-18 5:36 [PATCH] driver: video: Check allocated pointers Bin Meng
@ 2022-06-25 7:10 ` Anatolij Gustschin
0 siblings, 0 replies; 2+ messages in thread
From: Anatolij Gustschin @ 2022-06-25 7:10 UTC (permalink / raw)
To: Bin Meng; +Cc: u-boot
On Wed, 18 May 2022 13:36:18 +0800
Bin Meng bmeng.cn@gmail.com wrote:
> The codes that call STBTT_malloc() / stbtt__new_active() do not check
> the return value at present which may cause segfault.
>
> Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
> ---
>
> drivers/video/stb_truetype.h | 18 ++++++++++++++----
> 1 file changed, 14 insertions(+), 4 deletions(-)
applied to u-boot-video/master, thanks!
--
Anatolij
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-06-25 7:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-18 5:36 [PATCH] driver: video: Check allocated pointers Bin Meng
2022-06-25 7:10 ` Anatolij Gustschin
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.