[SECURITY FIX] Fix CVE-2014-3483 and protect against CVE-2014-3482

This is literally translated patch from http://seclists.org/oss-sec/2014/q3/5