Skip to content

Commit 5957f97

Browse files
committed
Convert php_network_getaddress* to use unsigned size_t
Since this can never return -1 (0 on error/none, >0 for addresses)
1 parent fcc6ba8 commit 5957f97

6 files changed

Lines changed: 15 additions & 14 deletions

File tree

ext/snmp/snmp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ static bool snmp_session_init(php_snmp_session **session_p, int version, zend_st
832832
php_snmp_session *session;
833833
char *pptr, *host_ptr;
834834
bool force_ipv6 = false;
835-
int n;
835+
size_t n;
836836
struct sockaddr **psal;
837837
struct sockaddr **res;
838838

ext/standard/dns.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ PHP_FUNCTION(gethostbyname)
233233
}
234234

235235
php_sockaddr_storage resolved;
236-
int address_count = php_network_getaddress(&resolved, hostname, 0, AF_INET, 0, NULL);
236+
size_t address_count = php_network_getaddress(&resolved, hostname, 0, AF_INET, 0, NULL);
237237
if (address_count == 0) {
238238
/* don't need to docref here, getaddresses E_WARNINGs for us */
239239
RETURN_STRINGL(hostname, hostname_len);
@@ -276,7 +276,7 @@ PHP_FUNCTION(gethostbynamel)
276276
}
277277

278278
struct sockaddr **addresses = NULL;
279-
int address_count = php_network_getaddresses(hostname, 0, &addresses, NULL);
279+
size_t address_count = php_network_getaddresses(hostname, 0, &addresses, NULL);
280280
if (address_count == 0) {
281281
/* don't need to docref here, getaddresses E_WARNINGs for us */
282282
RETURN_FALSE;

main/fastcgi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ int fcgi_listen(const char *path, int backlog)
683683
} else {
684684
if (!inet_pton(AF_INET, host, &sa.sa_inet.sin_addr)) {
685685
php_sockaddr_storage resolved;
686-
int address_count;
686+
size_t address_count;
687687

688688
if (strlen(host) > MAXFQDNLEN) {
689689
address_count = 0;

main/network.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,11 @@ PHPAPI void php_network_freeaddresses(struct sockaddr **sal)
145145
/* {{{ php_network_getaddresses_ex
146146
* Returns number of addresses, 0 for none/error
147147
*/
148-
PHPAPI int php_network_getaddresses_ex(const char *host, int socktype, int family, int ai_flags, struct sockaddr ***sal, zend_string **error_string)
148+
PHPAPI size_t php_network_getaddresses_ex(const char *host, int socktype, int family, int ai_flags, struct sockaddr ***sal, zend_string **error_string)
149149
{
150150
struct sockaddr **sap;
151-
int n;
151+
size_t n;
152+
int ret;
152153
#ifdef HAVE_GETADDRINFO
153154
# ifdef HAVE_IPV6
154155
static int ipv6_borked = -1; /* the way this is used *is* thread safe */
@@ -190,7 +191,7 @@ PHPAPI int php_network_getaddresses_ex(const char *host, int socktype, int famil
190191
hints.ai_family = ipv6_borked ? AF_INET : family;
191192
# endif
192193

193-
if ((n = getaddrinfo(host, NULL, &hints, &res))) {
194+
if ((ret = getaddrinfo(host, NULL, &hints, &res))) {
194195
# if defined(PHP_WIN32)
195196
char *gai_error = php_win32_error_to_msg(n);
196197
# elif defined(HAVE_GAI_STRERROR)
@@ -253,7 +254,7 @@ PHPAPI int php_network_getaddresses_ex(const char *host, int socktype, int famil
253254
/* {{{ php_network_getaddresses
254255
* Returns number of addresses, 0 for none/error
255256
*/
256-
PHPAPI int php_network_getaddresses(const char *host, int socktype, struct sockaddr ***sal, zend_string **error_string)
257+
PHPAPI size_t php_network_getaddresses(const char *host, int socktype, struct sockaddr ***sal, zend_string **error_string)
257258
{
258259
return php_network_getaddresses_ex(host, socktype, AF_UNSPEC, 0, sal, error_string);
259260
}
@@ -262,10 +263,10 @@ PHPAPI int php_network_getaddresses(const char *host, int socktype, struct socka
262263
/* {{{ php_network_getaddress
263264
* Returns the number of addresses, and puts first address for a hostname in sockaddr.
264265
*/
265-
PHPAPI int php_network_getaddress(php_sockaddr_storage *sockaddr, const char *host, int socktype, int family, int ai_flags, zend_string **error_string)
266+
PHPAPI size_t php_network_getaddress(php_sockaddr_storage *sockaddr, const char *host, int socktype, int family, int ai_flags, zend_string **error_string)
266267
{
267268
struct sockaddr** addresses;
268-
int address_count = php_network_getaddresses_ex(host, socktype, family, ai_flags, &addresses, error_string);
269+
size_t address_count = php_network_getaddresses_ex(host, socktype, family, ai_flags, &addresses, error_string);
269270
if (address_count == 0) {
270271
return 0;
271272
}

main/php_network.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,10 @@ typedef struct {
285285
} php_sockvals;
286286

287287
BEGIN_EXTERN_C()
288-
PHPAPI int php_network_getaddresses(const char *host, int socktype, struct sockaddr ***sal, zend_string **error_string);
289-
PHPAPI int php_network_getaddresses_ex(const char *host, int socktype, int family, int ai_flags, struct sockaddr ***sal, zend_string **error_string);
288+
PHPAPI size_t php_network_getaddresses(const char *host, int socktype, struct sockaddr ***sal, zend_string **error_string);
289+
PHPAPI size_t php_network_getaddresses_ex(const char *host, int socktype, int family, int ai_flags, struct sockaddr ***sal, zend_string **error_string);
290290
PHPAPI void php_network_freeaddresses(struct sockaddr **sal);
291-
PHPAPI int php_network_getaddress(php_sockaddr_storage *sockaddr, const char *host, int socktype, int family, int ai_flags, zend_string **error_string);
291+
PHPAPI size_t php_network_getaddress(php_sockaddr_storage *sockaddr, const char *host, int socktype, int family, int ai_flags, zend_string **error_string);
292292

293293
PHPAPI php_socket_t php_network_connect_socket_to_host_ex(const char *host, unsigned short port,
294294
int socktype, int asynchronous, struct timeval *timeout, zend_string **error_string,

sapi/cli/php_cli_server.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1275,7 +1275,7 @@ static php_socket_t php_network_listen_socket(const char *host, int *port, int s
12751275
int err = 0;
12761276
struct sockaddr *sa = NULL, **p, **sal;
12771277

1278-
int num_addrs = php_network_getaddresses(host, socktype, &sal, errstr);
1278+
size_t num_addrs = php_network_getaddresses(host, socktype, &sal, errstr);
12791279
if (num_addrs == 0) {
12801280
return -1;
12811281
}

0 commit comments

Comments
 (0)