Skip to content

Commit

Permalink
kmsdrm: Add missing checks after SDL_calloc() calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
vanfanel committed Oct 22, 2020
1 parent ad9ec8b commit b1ea0be
Showing 1 changed file with 36 additions and 10 deletions.
46 changes: 36 additions & 10 deletions src/video/kmsdrm/SDL_kmsdrmvideo.c
Expand Up @@ -545,6 +545,9 @@ setup_plane(_THIS, struct plane **plane, uint32_t plane_type)
SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata);

*plane = SDL_calloc(1, sizeof(**plane));
if (!(*plane)) {
return SDL_OutOfMemory();
}

/* Get plane ID. */
plane_id = get_plane_id(_this, plane_type);
Expand All @@ -561,10 +564,14 @@ setup_plane(_THIS, struct plane **plane, uint32_t plane_type)
unsigned int i;
(*plane)->props = KMSDRM_drmModeObjectGetProperties(viddata->drm_fd,
(*plane)->plane->plane_id, DRM_MODE_OBJECT_PLANE);

(*plane)->props_info = SDL_calloc((*plane)->props->count_props,
sizeof(*(*plane)->props_info));

if ( !((*plane)->props_info) ) {
SDL_OutOfMemory();
goto cleanup;
}

for (i = 0; i < (*plane)->props->count_props; i++) {
(*plane)->props_info[i] = KMSDRM_drmModeGetProperty(viddata->drm_fd,
(*plane)->props->props[i]);
Expand Down Expand Up @@ -876,7 +883,6 @@ KMSDRM_FBFromBO(_THIS, struct gbm_bo *bo)
/* Create a structure that contains the info about framebuffer
that we need to use it. */
fb_info = (KMSDRM_FBInfo *)SDL_calloc(1, sizeof(KMSDRM_FBInfo));

if (!fb_info) {
SDL_OutOfMemory();
return NULL;
Expand Down Expand Up @@ -1139,9 +1145,16 @@ KMSDRM_VideoInit(_THIS)
SDL_VideoDisplay display = {0};

dispdata = (SDL_DisplayData *) SDL_calloc(1, sizeof(SDL_DisplayData));
if (!dispdata) {
return SDL_OutOfMemory();
}

dispdata->display_plane = SDL_calloc(1, sizeof(*dispdata->display_plane));
dispdata->crtc = SDL_calloc(1, sizeof(*dispdata->crtc));
dispdata->connector = SDL_calloc(1, sizeof(*dispdata->connector));
if (!(dispdata->display_plane) || !(dispdata->crtc) || !(dispdata->connector)) {
return SDL_OutOfMemory();
}

dispdata->atomic_flags = 0;
dispdata->atomic_req = NULL;
Expand All @@ -1151,10 +1164,6 @@ KMSDRM_VideoInit(_THIS)
dispdata->dumb_buffer = NULL;
dispdata->modeset_pending = SDL_FALSE;

if (!dispdata) {
return SDL_OutOfMemory();
}

SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "KMSDRM_VideoInit()");

/* Open /dev/dri/cardNN */
Expand Down Expand Up @@ -1337,6 +1346,11 @@ KMSDRM_VideoInit(_THIS)

dispdata->crtc->props_info = SDL_calloc(dispdata->crtc->props->count_props,
sizeof(*dispdata->crtc->props_info));

if (!dispdata->crtc->props_info) {
ret = SDL_OutOfMemory();
goto cleanup;
}

for (i = 0; i < dispdata->crtc->props->count_props; i++) {
dispdata->crtc->props_info[i] = KMSDRM_drmModeGetProperty(viddata->drm_fd,
Expand All @@ -1350,6 +1364,11 @@ KMSDRM_VideoInit(_THIS)
dispdata->connector->props_info = SDL_calloc(dispdata->connector->props->count_props,
sizeof(*dispdata->connector->props_info));

if (!dispdata->connector->props_info) {
ret = SDL_OutOfMemory();
goto cleanup;
}

for (i = 0; i < dispdata->connector->props->count_props; i++) {
dispdata->connector->props_info[i] = KMSDRM_drmModeGetProperty(viddata->drm_fd,
dispdata->connector->props->props[i]);
Expand Down Expand Up @@ -1579,9 +1598,12 @@ KMSDRM_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
for (i = 0; i < conn->count_modes; i++) {
SDL_DisplayModeData *modedata = SDL_calloc(1, sizeof(SDL_DisplayModeData));

if (modedata) {
modedata->mode_index = i;
if (!modedata) {
SDL_OutOfMemory();
return;
}

modedata->mode_index = i;

mode.w = conn->modes[i].hdisplay;
mode.h = conn->modes[i].vdisplay;
Expand Down Expand Up @@ -1651,13 +1673,17 @@ KMSDRM_CreateWindow(_THIS, SDL_Window * window)

/* Allocate window internal data */
windata = (SDL_WindowData *)SDL_calloc(1, sizeof(SDL_WindowData));
if (!windata) {
SDL_OutOfMemory();
goto error;
}

display = SDL_GetDisplayForWindow(window);
dispdata = display->driverdata;

if (((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) ||
((window->flags & SDL_WINDOW_FULLSCREEN) == SDL_WINDOW_FULLSCREEN)) {

((window->flags & SDL_WINDOW_FULLSCREEN) == SDL_WINDOW_FULLSCREEN))
{
windata->src_w = dispdata->mode.hdisplay;
windata->src_h = dispdata->mode.vdisplay;
windata->output_w = dispdata->mode.hdisplay;
Expand Down

0 comments on commit b1ea0be

Please sign in to comment.