summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStanislav Malyshev <stas@php.net>2015-01-31 19:08:37 -0800
committerStanislav Malyshev <stas@php.net>2015-01-31 19:08:37 -0800
commit237128603f99a97da9d0d261b8d0849f27b4c7b8 (patch)
treeb22950edbec46949e587be43acc15fa4100bd5e1
parentc8a12508c748a546d9dab14b3eb2c4a94ca279cc (diff)
parent0f9c708229d7d4f4eff96c30cff7a2339f738511 (diff)
downloadphp-git-237128603f99a97da9d0d261b8d0849f27b4c7b8.tar.gz
Merge branch 'PHP-5.4' into PHP-5.5
* PHP-5.4: Add mitigation for CVE-2015-0235 (bug #68925)
-rw-r--r--ext/standard/dns.c11
-rw-r--r--ext/standard/tests/network/bug68925.phpt13
-rw-r--r--main/network.c12
-rw-r--r--sapi/cgi/fastcgi.c6
4 files changed, 40 insertions, 2 deletions
diff --git a/ext/standard/dns.c b/ext/standard/dns.c
index 7d95a22abf..bb5f9109ed 100644
--- a/ext/standard/dns.c
+++ b/ext/standard/dns.c
@@ -222,6 +222,11 @@ PHP_FUNCTION(gethostbyname)
return;
}
+ if(hostname_len > MAXHOSTNAMELEN) {
+ /* name too long, protect from CVE-2015-0235 */
+ php_error_docref(NULL, E_WARNING, "Host name is too long, the limit is %d characters", MAXHOSTNAMELEN);
+ RETURN_STRINGL(hostname, hostname_len, 1);
+ }
addr = php_gethostbyname(hostname);
RETVAL_STRING(addr, 0);
@@ -242,6 +247,12 @@ PHP_FUNCTION(gethostbynamel)
return;
}
+ if(hostname_len > MAXHOSTNAMELEN) {
+ /* name too long, protect from CVE-2015-0235 */
+ php_error_docref(NULL, E_WARNING, "Host name is too long, the limit is %d characters", MAXHOSTNAMELEN);
+ RETURN_FALSE;
+ }
+
hp = gethostbyname(hostname);
if (hp == NULL || hp->h_addr_list == NULL) {
RETURN_FALSE;
diff --git a/ext/standard/tests/network/bug68925.phpt b/ext/standard/tests/network/bug68925.phpt
new file mode 100644
index 0000000000..e710d72bdf
--- /dev/null
+++ b/ext/standard/tests/network/bug68925.phpt
@@ -0,0 +1,13 @@
+--TEST--
+Bug #68925 (CVE-2015-0235 – GHOST: glibc gethostbyname buffer overflow)
+--FILE--
+<?php
+var_dump(gethostbyname(str_repeat("0", 2501)));
+var_dump(gethostbynamel(str_repeat("0", 2501)));
+?>
+--EXPECTF--
+Warning: gethostbyname(): Host name is too long, the limit is 256 characters in %s/bug68925.php on line %d
+string(2501) "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
+
+Warning: gethostbynamel(): Host name is too long, the limit is 256 characters in %s/bug68925.php on line %d
+bool(false)
diff --git a/main/network.c b/main/network.c
index 6072e76e72..702509a9d9 100644
--- a/main/network.c
+++ b/main/network.c
@@ -24,6 +24,7 @@
#include "php.h"
#include <stddef.h>
+#include <errno.h>
@@ -105,6 +106,10 @@ const struct in6_addr in6addr_any = {0}; /* IN6ADDR_ANY_INIT; */
# define PHP_TIMEOUT_ERROR_VALUE ETIMEDOUT
#endif
+#ifndef MAXHOSTNAMELEN
+#define MAXHOSTNAMELEN 255
+#endif
+
#if HAVE_GETADDRINFO
#ifdef HAVE_GAI_STRERROR
# define PHP_GAI_STRERROR(x) (gai_strerror(x))
@@ -246,7 +251,12 @@ PHPAPI int php_network_getaddresses(const char *host, int socktype, struct socka
#else
if (!inet_aton(host, &in)) {
/* XXX NOT THREAD SAFE (is safe under win32) */
- host_info = gethostbyname(host);
+ if(strlen(host) > MAXHOSTNAMELEN) {
+ host_info = NULL;
+ errno = E2BIG;
+ } else {
+ host_info = gethostbyname(host);
+ }
if (host_info == NULL) {
if (error_string) {
spprintf(error_string, 0, "php_network_getaddresses: gethostbyname failed. errno=%d", errno);
diff --git a/sapi/cgi/fastcgi.c b/sapi/cgi/fastcgi.c
index 5e9e4c89c4..7d39d6139b 100644
--- a/sapi/cgi/fastcgi.c
+++ b/sapi/cgi/fastcgi.c
@@ -611,7 +611,11 @@ int fcgi_listen(const char *path, int backlog)
if (sa.sa_inet.sin_addr.s_addr == INADDR_NONE) {
struct hostent *hep;
- hep = gethostbyname(host);
+ if(strlen(host) > MAXHOSTNAMELEN) {
+ hep = NULL;
+ } else {
+ hep = gethostbyname(host);
+ }
if (!hep || hep->h_addrtype != AF_INET || !hep->h_addr_list[0]) {
fprintf(stderr, "Cannot resolve host name '%s'!\n", host);
return -1;