MISC security fixes

Stuff that I've had for ages locally... and that should probably get in the next release.
In general I agree with the coding style rules. Tabs are bad, we should use spaces, but having **mixed** indentation is far worse. Either adapt the entire file to use spaces, or stick to using tabs here.