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 7046 8d5636aafd1c
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
--- a/src/video/SDL_video.c	Tue Apr 02 07:57:37 2013 -0700
+++ b/src/video/SDL_video.c	Tue Apr 02 08:38:52 2013 -0700
@@ -1425,11 +1425,17 @@
     SDL_WindowUserData *prev, *data;
 
     CHECK_WINDOW_MAGIC(window, NULL);
+    
+    /* Input validation */
+    if (name == NULL || SDL_strlen(name) == 0) {
+      SDL_InvalidParamError("name");
+      return NULL;
+    }
 
     /* See if the named data already exists */
     prev = NULL;
     for (data = window->data; data; prev = data, data = data->next) {
-        if (SDL_strcmp(data->name, name) == 0) {
+        if (data->name && SDL_strcmp(data->name, name) == 0) {
             void *last_value = data->data;
 
             if (userdata) {
@@ -1467,8 +1473,14 @@
 
     CHECK_WINDOW_MAGIC(window, NULL);
 
+    /* Input validation */
+    if (name == NULL || SDL_strlen(name) == 0) {
+      SDL_InvalidParamError("name");
+      return NULL;
+    }
+
     for (data = window->data; data; data = data->next) {
-        if (SDL_strcmp(data->name, name) == 0) {
+        if (data->name && SDL_strcmp(data->name, name) == 0) {
             return data->data;
         }
     }