Add input validation and null checking to SDL_Get/SetWindowData [reported by Joseph T.]
authorAndreas Schiffler <aschiffler@ferzkopp.net>
Tue, 02 Apr 2013 08:38:52 -0700
changeset 70468d5636aafd1c
parent 7045 4be2c24b7de1
child 7047 299de3271a7b
Add input validation and null checking to SDL_Get/SetWindowData [reported by Joseph T.]
src/video/SDL_video.c
     1.1 --- a/src/video/SDL_video.c	Tue Apr 02 07:57:37 2013 -0700
     1.2 +++ b/src/video/SDL_video.c	Tue Apr 02 08:38:52 2013 -0700
     1.3 @@ -1425,11 +1425,17 @@
     1.4      SDL_WindowUserData *prev, *data;
     1.5  
     1.6      CHECK_WINDOW_MAGIC(window, NULL);
     1.7 +    
     1.8 +    /* Input validation */
     1.9 +    if (name == NULL || SDL_strlen(name) == 0) {
    1.10 +      SDL_InvalidParamError("name");
    1.11 +      return NULL;
    1.12 +    }
    1.13  
    1.14      /* See if the named data already exists */
    1.15      prev = NULL;
    1.16      for (data = window->data; data; prev = data, data = data->next) {
    1.17 -        if (SDL_strcmp(data->name, name) == 0) {
    1.18 +        if (data->name && SDL_strcmp(data->name, name) == 0) {
    1.19              void *last_value = data->data;
    1.20  
    1.21              if (userdata) {
    1.22 @@ -1467,8 +1473,14 @@
    1.23  
    1.24      CHECK_WINDOW_MAGIC(window, NULL);
    1.25  
    1.26 +    /* Input validation */
    1.27 +    if (name == NULL || SDL_strlen(name) == 0) {
    1.28 +      SDL_InvalidParamError("name");
    1.29 +      return NULL;
    1.30 +    }
    1.31 +
    1.32      for (data = window->data; data; data = data->next) {
    1.33 -        if (SDL_strcmp(data->name, name) == 0) {
    1.34 +        if (data->name && SDL_strcmp(data->name, name) == 0) {
    1.35              return data->data;
    1.36          }
    1.37      }