GH-79: backport supposed fix for CVE-2013-4852

"Add an assortment of extra safety checks."

Direct cherry-pick of svn://svn.tartarus.org/sgt/putty@9896