Security Fixes

These changes fix a few security issues, one of which has been publicly documented since 2008.