Fix CVE-2014-8767, CVE-2014-8768, CVE-2014-8769 and CVE-2014-9140

Upstream security fixes, backported by ubuntu/debian.