get rid of inet_addr and gethostbyaddr calls
This commit is contained in:
parent
a5703f401f
commit
2201155ebf
@ -284,3 +284,117 @@ index 2c504952b2dd1..7f2f714ec42df 100644
|
|||||||
php_error_docref(NULL, E_WARNING, "Invalid IP Address: %s", bindto);
|
php_error_docref(NULL, E_WARNING, "Invalid IP Address: %s", bindto);
|
||||||
goto skip_bind;
|
goto skip_bind;
|
||||||
}
|
}
|
||||||
|
From e5b6f43ec7813392d83ea586b7902e0396a1f792 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Remi Collet <remi@remirepo.net>
|
||||||
|
Date: Thu, 6 May 2021 14:21:29 +0200
|
||||||
|
Subject: [PATCH] get rid of inet_addr usage
|
||||||
|
|
||||||
|
---
|
||||||
|
main/fastcgi.c | 4 ++++
|
||||||
|
sapi/litespeed/lsapilib.c | 4 ++++
|
||||||
|
2 files changed, 8 insertions(+)
|
||||||
|
|
||||||
|
diff --git a/main/fastcgi.c b/main/fastcgi.c
|
||||||
|
index 071f69d3a7f0..c936d42405de 100644
|
||||||
|
--- a/main/fastcgi.c
|
||||||
|
+++ b/main/fastcgi.c
|
||||||
|
@@ -688,8 +688,12 @@ int fcgi_listen(const char *path, int backlog)
|
||||||
|
if (!*host || !strncmp(host, "*", sizeof("*")-1)) {
|
||||||
|
sa.sa_inet.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||||
|
} else {
|
||||||
|
+#ifdef HAVE_INET_PTON
|
||||||
|
+ if (!inet_pton(AF_INET, host, &sa.sa_inet.sin_addr)) {
|
||||||
|
+#else
|
||||||
|
sa.sa_inet.sin_addr.s_addr = inet_addr(host);
|
||||||
|
if (sa.sa_inet.sin_addr.s_addr == INADDR_NONE) {
|
||||||
|
+#endif
|
||||||
|
struct hostent *hep;
|
||||||
|
|
||||||
|
if(strlen(host) > MAXFQDNLEN) {
|
||||||
|
diff --git a/sapi/litespeed/lsapilib.c b/sapi/litespeed/lsapilib.c
|
||||||
|
index a72b5dc1b988..305f3326a682 100644
|
||||||
|
--- a/sapi/litespeed/lsapilib.c
|
||||||
|
+++ b/sapi/litespeed/lsapilib.c
|
||||||
|
@@ -2672,8 +2672,12 @@ int LSAPI_ParseSockAddr( const char * pBind, struct sockaddr * pAddr )
|
||||||
|
((struct sockaddr_in *)pAddr)->sin_addr.s_addr = htonl( INADDR_LOOPBACK );
|
||||||
|
else
|
||||||
|
{
|
||||||
|
+#ifdef HAVE_INET_PTON
|
||||||
|
+ if (!inet_pton(AF_INET, p, &((struct sockaddr_in *)pAddr)->sin_addr))
|
||||||
|
+#else
|
||||||
|
((struct sockaddr_in *)pAddr)->sin_addr.s_addr = inet_addr( p );
|
||||||
|
if ( ((struct sockaddr_in *)pAddr)->sin_addr.s_addr == INADDR_BROADCAST)
|
||||||
|
+#endif
|
||||||
|
{
|
||||||
|
doAddrInfo = 1;
|
||||||
|
}
|
||||||
|
From 99d67d121acd4c324738509679d23acaf759d065 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Remi Collet <remi@remirepo.net>
|
||||||
|
Date: Thu, 6 May 2021 16:35:48 +0200
|
||||||
|
Subject: [PATCH] use getnameinfo instead of gethostbyaddr
|
||||||
|
|
||||||
|
---
|
||||||
|
ext/standard/dns.c | 34 ++++++++++++++++++++++------------
|
||||||
|
1 file changed, 22 insertions(+), 12 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/ext/standard/dns.c b/ext/standard/dns.c
|
||||||
|
index edd9a4549f5c..540c777faaba 100644
|
||||||
|
--- a/ext/standard/dns.c
|
||||||
|
+++ b/ext/standard/dns.c
|
||||||
|
@@ -169,20 +169,30 @@ PHP_FUNCTION(gethostbyaddr)
|
||||||
|
static zend_string *php_gethostbyaddr(char *ip)
|
||||||
|
{
|
||||||
|
#if HAVE_IPV6 && HAVE_INET_PTON
|
||||||
|
- struct in6_addr addr6;
|
||||||
|
-#endif
|
||||||
|
- struct in_addr addr;
|
||||||
|
- struct hostent *hp;
|
||||||
|
+ struct sockaddr_in sa4;
|
||||||
|
+ struct sockaddr_in6 sa6;
|
||||||
|
+ char out[NI_MAXHOST];
|
||||||
|
|
||||||
|
-#if HAVE_IPV6 && HAVE_INET_PTON
|
||||||
|
- if (inet_pton(AF_INET6, ip, &addr6)) {
|
||||||
|
- hp = gethostbyaddr((char *) &addr6, sizeof(addr6), AF_INET6);
|
||||||
|
- } else if (inet_pton(AF_INET, ip, &addr)) {
|
||||||
|
- hp = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET);
|
||||||
|
- } else {
|
||||||
|
- return NULL;
|
||||||
|
+ if (inet_pton(AF_INET6, ip, &sa6.sin6_addr)) {
|
||||||
|
+ sa6.sin6_family = AF_INET6;
|
||||||
|
+
|
||||||
|
+ if (getnameinfo((struct sockaddr *)&sa6, sizeof(sa6), out, sizeof(out), NULL, 0, NI_NAMEREQD) < 0) {
|
||||||
|
+ return zend_string_init(ip, strlen(ip), 0);
|
||||||
|
+ }
|
||||||
|
+ return zend_string_init(out, strlen(out), 0);
|
||||||
|
+ } else if (inet_pton(AF_INET, ip, &sa4.sin_addr)) {
|
||||||
|
+ sa4.sin_family = AF_INET;
|
||||||
|
+
|
||||||
|
+ if (getnameinfo((struct sockaddr *)&sa4, sizeof(sa4), out, sizeof(out), NULL, 0, NI_NAMEREQD) < 0) {
|
||||||
|
+ return zend_string_init(ip, strlen(ip), 0);
|
||||||
|
+ }
|
||||||
|
+ return zend_string_init(out, strlen(out), 0);
|
||||||
|
}
|
||||||
|
+ return NULL; /* not a valid IP */
|
||||||
|
#else
|
||||||
|
+ struct in_addr addr;
|
||||||
|
+ struct hostent *hp;
|
||||||
|
+
|
||||||
|
addr.s_addr = inet_addr(ip);
|
||||||
|
|
||||||
|
if (addr.s_addr == -1) {
|
||||||
|
@@ -190,13 +200,13 @@ static zend_string *php_gethostbyaddr(char *ip)
|
||||||
|
}
|
||||||
|
|
||||||
|
hp = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET);
|
||||||
|
-#endif
|
||||||
|
|
||||||
|
if (!hp || hp->h_name == NULL || hp->h_name[0] == '\0') {
|
||||||
|
return zend_string_init(ip, strlen(ip), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return zend_string_init(hp->h_name, strlen(hp->h_name), 0);
|
||||||
|
+#endif
|
||||||
|
}
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
|
5
php.spec
5
php.spec
@ -62,7 +62,7 @@
|
|||||||
Summary: PHP scripting language for creating dynamic web sites
|
Summary: PHP scripting language for creating dynamic web sites
|
||||||
Name: php
|
Name: php
|
||||||
Version: %{upver}%{?rcver:~%{rcver}}
|
Version: %{upver}%{?rcver:~%{rcver}}
|
||||||
Release: 2%{?dist}
|
Release: 3%{?dist}
|
||||||
# All files licensed under PHP version 3.01, except
|
# All files licensed under PHP version 3.01, except
|
||||||
# Zend is licensed under Zend
|
# Zend is licensed under Zend
|
||||||
# TSRM is licensed under BSD
|
# TSRM is licensed under BSD
|
||||||
@ -1521,6 +1521,9 @@ systemctl try-restart php-fpm.service >/dev/null 2>&1 || :
|
|||||||
|
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Sat May 8 2021 Remi Collet <remi@remirepo.net> - 8.0.6-3
|
||||||
|
- get rid of inet_addr and gethostbyaddr calls
|
||||||
|
|
||||||
* Thu May 6 2021 Remi Collet <remi@remirepo.net> - 8.0.6-2
|
* Thu May 6 2021 Remi Collet <remi@remirepo.net> - 8.0.6-2
|
||||||
- get rid of inet_ntoa and inet_aton calls
|
- get rid of inet_ntoa and inet_aton calls
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user