Memory fixes (#1705)

* fix: free-before-init in renwin_init_surface when using sdl renderer

`ren->rensurface.surface` presupposes zero-initialized rensurface.
Rensurface was not actually zero-initialized.
It is now.

* fix: heap buffer overflow in process_env_free

`process_env_free` presupposed that it was null-terminated.
Pass length to free instead.

* use calloc instead of memset for zero-init

Co-authored-by: Guldoman <giulio.lettieri@gmail.com>

---------

Co-authored-by: Guldoman <giulio.lettieri@gmail.com>
This commit is contained in:
Chloé Vulquin 2024-01-20 01:02:46 +01:00 committed by takase1121
parent 2ce8c58bea
commit 4ae92ae128
No known key found for this signature in database
GPG Key ID: 60EEFFC68EB3031B
1 changed files with 3 additions and 3 deletions

View File

@ -560,12 +560,12 @@ static int process_env_add(process_env_t *env_list, size_t *env_len, const char
} }
static void process_env_free(process_env_t *list) { static void process_env_free(process_env_t *list, size_t list_len) {
if (!*list) return; if (!*list) return;
#ifdef _WIN32 #ifdef _WIN32
free(*list); free(*list);
#else #else
for (size_t i = 0; (*list)[i]; i++) free((*list)[i]); for (size_t i = 0; i < list_len; i++) free((*list)[i]);
free(*list); free(*list);
#endif #endif
*list = NULL; *list = NULL;
@ -830,7 +830,7 @@ static int process_start(lua_State* L) {
} }
} }
process_arglist_free(&arglist); process_arglist_free(&arglist);
process_env_free(&env_vars); process_env_free(&env_vars, env_vars_len);
if (retval == -1) if (retval == -1)
return lua_error(L); return lua_error(L);