Skip to content

Commit 141b144

Browse files
committed
Merge branch 'PHP-5.6'
* PHP-5.6: Use better constant since MAXHOSTNAMELEN may mean shorter name use right sizeof for memset Conflicts: ext/sockets/sockaddr_conv.c ext/standard/dns.c
2 parents 02fcbe0 + 6a960b6 commit 141b144

File tree

7 files changed

+19
-19
lines changed

7 files changed

+19
-19
lines changed

ext/sockets/sockaddr_conv.c

+2-6
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@
99
#include <arpa/inet.h>
1010
#endif
1111

12-
#ifndef MAXHOSTNAMELEN
13-
#define MAXHOSTNAMELEN 255
14-
#endif
15-
16-
extern int php_string_to_if_index(const char *val, unsigned *out);
12+
extern int php_string_to_if_index(const char *val, unsigned *out TSRMLS_DC);
1713

1814
#if HAVE_IPV6
1915
/* Sets addr by hostname, or by ip in string form (AF_INET6) */
@@ -94,7 +90,7 @@ int php_set_inet_addr(struct sockaddr_in *sin, char *string, php_socket *php_soc
9490
if (inet_aton(string, &tmp)) {
9591
sin->sin_addr.s_addr = tmp.s_addr;
9692
} else {
97-
if (strlen(string) > MAXHOSTNAMELEN || ! (host_entry = gethostbyname(string))) {
93+
if (strlen(string) > MAXFQDNLEN || ! (host_entry = gethostbyname(string))) {
9894
/* Note: < -10000 indicates a host lookup error */
9995
#ifdef PHP_WIN32
10096
PHP_SOCKET_ERROR(php_sock, "Host lookup failed", WSAGetLastError());

ext/standard/dns.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,9 @@ PHP_FUNCTION(gethostbyname)
221221
return;
222222
}
223223

224-
if(hostname_len > MAXHOSTNAMELEN) {
224+
if(hostname_len > MAXFQDNLEN) {
225225
/* name too long, protect from CVE-2015-0235 */
226-
php_error_docref(NULL, E_WARNING, "Host name is too long, the limit is %d characters", MAXHOSTNAMELEN);
226+
php_error_docref(NULL, E_WARNING, "Host name is too long, the limit is %d characters", MAXFQDNLEN);
227227
RETURN_STRINGL(hostname, hostname_len);
228228
}
229229

@@ -245,9 +245,9 @@ PHP_FUNCTION(gethostbynamel)
245245
return;
246246
}
247247

248-
if(hostname_len > MAXHOSTNAMELEN) {
248+
if(hostname_len > MAXFQDNLEN) {
249249
/* name too long, protect from CVE-2015-0235 */
250-
php_error_docref(NULL, E_WARNING, "Host name is too long, the limit is %d characters", MAXHOSTNAMELEN);
250+
php_error_docref(NULL, E_WARNING, "Host name is too long, the limit is %d characters", MAXFQDNLEN);
251251
RETURN_FALSE;
252252
}
253253

ext/standard/tests/network/bug68925.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ var_dump(gethostbyname(str_repeat("0", 2501)));
66
var_dump(gethostbynamel(str_repeat("0", 2501)));
77
?>
88
--EXPECTF--
9-
Warning: gethostbyname(): Host name is too long, the limit is 256 characters in %s/bug68925.php on line %d
9+
Warning: gethostbyname(): Host name is too long, the limit is %d characters in %s/bug68925.php on line %d
1010
string(2501) "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
1111

12-
Warning: gethostbynamel(): Host name is too long, the limit is 256 characters in %s/bug68925.php on line %d
12+
Warning: gethostbynamel(): Host name is too long, the limit is %d characters in %s/bug68925.php on line %d
1313
bool(false)

main/network.c

+1-5
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,6 @@ const struct in6_addr in6addr_any = {0}; /* IN6ADDR_ANY_INIT; */
105105
# define PHP_TIMEOUT_ERROR_VALUE ETIMEDOUT
106106
#endif
107107

108-
#ifndef MAXHOSTNAMELEN
109-
#define MAXHOSTNAMELEN 255
110-
#endif
111-
112108
#if HAVE_GETADDRINFO
113109
#ifdef HAVE_GAI_STRERROR
114110
# define PHP_GAI_STRERROR(x) (gai_strerror(x))
@@ -250,7 +246,7 @@ PHPAPI int php_network_getaddresses(const char *host, int socktype, struct socka
250246
#else
251247
if (!inet_aton(host, &in)) {
252248
/* XXX NOT THREAD SAFE (is safe under win32) */
253-
if(strlen(host) > MAXHOSTNAMELEN) {
249+
if(strlen(host) > MAXFQDNLEN) {
254250
host_info = NULL;
255251
errno = E2BIG;
256252
} else {

main/php_network.h

+4
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,10 @@ END_EXTERN_C()
319319

320320
/* }}} */
321321

322+
#ifndef MAXFQDNLEN
323+
#define MAXFQDNLEN 255
324+
#endif
325+
322326
#endif /* _PHP_NETWORK_H */
323327

324328
/*

sapi/cgi/fastcgi.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
#include <stdarg.h>
2929
#include <errno.h>
3030

31+
#ifndef MAXFQDNLEN
32+
#define MAXFQDNLEN 255
33+
#endif
34+
3135
#ifdef _WIN32
3236

3337
#include <windows.h>
@@ -616,7 +620,7 @@ int fcgi_listen(const char *path, int backlog)
616620
if (sa.sa_inet.sin_addr.s_addr == INADDR_NONE) {
617621
struct hostent *hep;
618622

619-
if(strlen(host) > MAXHOSTNAMELEN) {
623+
if(strlen(host) > MAXFQDNLEN) {
620624
hep = NULL;
621625
} else {
622626
hep = gethostbyname(host);

sapi/litespeed/lsapilib.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3376,7 +3376,7 @@ void lsapi_MD5Final(unsigned char digest[16], struct lsapi_MD5Context *ctx)
33763376
lsapi_MD5Transform(ctx->buf, (uint32 *) ctx->in);
33773377
byteReverse((unsigned char *) ctx->buf, 4);
33783378
memmove(digest, ctx->buf, 16);
3379-
memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
3379+
memset(ctx, 0, sizeof(*ctx)); /* In case it's sensitive */
33803380
}
33813381

33823382
/* The four core functions - F1 is optimized somewhat */

0 commit comments

Comments
 (0)