Added pointer validation and additional sanity check to IsValidSid().