sdl2-compat: SDL_RenderGeometryRaw: safe-guard against bad num_vertices or color ptr

From 98aa2fd7416a07916ffbdec9b8c142139fb564fe Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Wed, 31 Jan 2024 20:10:50 +0300
Subject: [PATCH] SDL_RenderGeometryRaw: safe-guard against bad num_vertices or
 color ptr

---
 src/sdl2_compat.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index 521ed14..485dad2 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -4264,9 +4264,17 @@ DECLSPEC int SDLCALL
 SDL_RenderGeometryRaw(SDL_Renderer *renderer, SDL_Texture *texture, const float *xy, int xy_stride, const SDL_Color *color, int color_stride, const float *uv, int uv_stride, int num_vertices, const void *indices, int num_indices, int size_indices)
 {
     int i, retval;
-    SDL_FColor *color3 = (SDL_FColor *) SDL3_stack_alloc(SDL_FColor, num_vertices);
     const char *color2 = (const char *) color;
+    SDL_FColor *color3;
 
+    if (num_vertices <= 0) {
+        return SDL3_InvalidParamError("num_vertices");
+    }
+    if (!color) {
+        return SDL3_InvalidParamError("color");
+    }
+
+    color3 = (SDL_FColor *) SDL3_stack_alloc(SDL_FColor, num_vertices);
     for (i = 0; i < num_vertices; ++i) {
         color3[i].r = color->r / 255.0f;
         color3[i].g = color->g / 255.0f;