Please find attached a patch implementing an old FIXME comment [1] about validating the event mask in ModifyWaitEvent(). To prevent callers of ModifyWaitEvent() from passing invalid flags that can be silently accepted, I propose adding two checks:
1. Prevent setting socket wait flags on an event that has no socket, mirroring line 600 of AddWaitEventToSet() [2].
2. Prevent promoting a non-latch event to a latch event through ModifyWaitEvent(). The setup for latch events is handled in AddWaitEventToSet(), but not supported in ModifyWaitEvent(). For example, AddWaitEventToSet() enforces "cannot wait on more than one latch" [3] per set, registering the latch pointer [4], and handles platform-specific latch behavior [5]. We do still allow the behavior documented in the comment for ModifyWaitEvent() [6] about setting a latch to NULL to disable it, and enabling again as a latch later.