pygame / src / event.c

Diff from to

src/event.c

     Py_RETURN_NONE;
 }
 
+static int
+CheckEventInRange(int evt)
+{
+    return evt >= 0 && evt < SDL_NUMEVENTS;
+}
+
 static PyObject*
 set_allowed (PyObject* self, PyObject* args)
 {
             if (!IntFromObjIndex (type, loop, &val))
                 return RAISE (PyExc_TypeError,
                               "type sequence must contain valid event types");
+            if(!CheckEventInRange(val))
+                return RAISE (PyExc_ValueError, "Invalid event in sequence");
             SDL_EventState ((Uint8)val, SDL_ENABLE);
         }
     }
     else if (type == Py_None)
         SDL_EventState ((Uint8)0xFF, SDL_IGNORE);
     else if (IntFromObj (type, &val))
+    {
+        if(!CheckEventInRange (val))
+            return RAISE (PyExc_ValueError, "Invalid event");
         SDL_EventState ((Uint8)val, SDL_ENABLE);
+    }
     else
         return RAISE (PyExc_TypeError, "type must be numeric or a sequence");
 
             if (!IntFromObjIndex (type, loop, &val))
                 return RAISE (PyExc_TypeError,
                               "type sequence must contain valid event types");
+            if(!CheckEventInRange(val))
+                return RAISE (PyExc_ValueError, "Invalid event in sequence");
             SDL_EventState ((Uint8)val, SDL_IGNORE);
         }
     }
     else if (type == Py_None)
-        SDL_EventState ((Uint8)0, SDL_IGNORE);
+        SDL_EventState ((Uint8)0xFF, SDL_IGNORE);
     else if (IntFromObj (type, &val))
+    {
+        if(!CheckEventInRange (val))
+            return RAISE (PyExc_ValueError, "Invalid event");
         SDL_EventState ((Uint8)val, SDL_IGNORE);
+    }
     else
         return RAISE (PyExc_TypeError, "type must be numeric or a sequence");
 
             if (!IntFromObjIndex (type, loop, &val))
                 return RAISE (PyExc_TypeError,
                               "type sequence must contain valid event types");
+            if(!CheckEventInRange(val))
+                return RAISE (PyExc_ValueError, "Invalid event in sequence");
             isblocked |= SDL_EventState ((Uint8)val, SDL_QUERY) == SDL_IGNORE;
         }
     }
     else if (IntFromObj (type, &val))
+    {
+        if(!CheckEventInRange (val))
+            return RAISE (PyExc_ValueError, "Invalid event");
         isblocked = SDL_EventState ((Uint8)val, SDL_QUERY) == SDL_IGNORE;
+    }
     else
         return RAISE (PyExc_TypeError, "type must be numeric or a sequence");
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.