Source

pygame / src / event.c

Diff from to

File 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");