@@ -13,7 +13,7 @@ extern zend_result php_string_to_if_index(const char *val, unsigned *out);
13
13
14
14
#ifdef HAVE_IPV6
15
15
/* Sets addr by hostname, or by ip in string form (AF_INET6) */
16
- int php_set_inet6_addr (struct sockaddr_in6 * sin6 , char * string , php_socket * php_sock ) /* {{{ */
16
+ zend_result php_set_inet6_addr (struct sockaddr_in6 * sin6 , char * string , php_socket * php_sock ) /* {{{ */
17
17
{
18
18
struct in6_addr tmp ;
19
19
#ifdef HAVE_GETADDRINFO
@@ -41,12 +41,12 @@ int php_set_inet6_addr(struct sockaddr_in6 *sin6, char *string, php_socket *php_
41
41
#else
42
42
PHP_SOCKET_ERROR (php_sock , "Host lookup failed" , (-10000 - h_errno ));
43
43
#endif
44
- return 0 ;
44
+ return FAILURE ;
45
45
}
46
46
if (addrinfo -> ai_family != PF_INET6 || addrinfo -> ai_addrlen != sizeof (struct sockaddr_in6 )) {
47
47
php_error_docref (NULL , E_WARNING , "Host lookup failed: Non AF_INET6 domain returned on AF_INET6 socket" );
48
48
freeaddrinfo (addrinfo );
49
- return 0 ;
49
+ return FAILURE ;
50
50
}
51
51
52
52
memcpy (& (sin6 -> sin6_addr .s6_addr ), ((struct sockaddr_in6 * )(addrinfo -> ai_addr ))-> sin6_addr .s6_addr , sizeof (struct in6_addr ));
@@ -55,36 +55,43 @@ int php_set_inet6_addr(struct sockaddr_in6 *sin6, char *string, php_socket *php_
55
55
#else
56
56
/* No IPv6 specific hostname resolution is available on this system? */
57
57
php_error_docref (NULL , E_WARNING , "Host lookup failed: getaddrinfo() not available on this system" );
58
- return 0 ;
58
+ return FAILURE ;
59
59
#endif
60
60
61
61
}
62
62
63
63
if (scope ) {
64
64
zend_long lval = 0 ;
65
65
double dval = 0 ;
66
- unsigned scope_id = 0 ;
67
-
66
+ uint32_t scope_id = 0 ;
68
67
scope ++ ;
69
68
69
+ if (* scope == '\0' ) {
70
+ zend_value_error ("scope cannot be empty" );
71
+ return FAILURE ;
72
+ }
73
+
74
+
70
75
if (IS_LONG == is_numeric_string (scope , strlen (scope ), & lval , & dval , 0 )) {
71
- if (lval > 0 && (zend_ulong )lval <= UINT_MAX ) {
72
- scope_id = lval ;
76
+ if (lval <= 0 || (zend_ulong )lval > UINT_MAX ) {
77
+ zend_value_error ("scope must be between 1 and %u" , UINT_MAX );
78
+ return FAILURE ;
73
79
}
80
+ scope_id = lval ;
74
81
} else {
75
82
php_string_to_if_index (scope , & scope_id );
76
83
}
77
84
78
85
sin6 -> sin6_scope_id = scope_id ;
79
86
}
80
87
81
- return 1 ;
88
+ return SUCCESS ;
82
89
}
83
90
/* }}} */
84
91
#endif
85
92
86
93
/* Sets addr by hostname, or by ip in string form (AF_INET) */
87
- int php_set_inet_addr (struct sockaddr_in * sin , char * string , php_socket * php_sock ) /* {{{ */
94
+ zend_result php_set_inet_addr (struct sockaddr_in * sin , char * string , php_socket * php_sock ) /* {{{ */
88
95
{
89
96
struct in_addr tmp ;
90
97
struct hostent * host_entry ;
@@ -99,46 +106,46 @@ int php_set_inet_addr(struct sockaddr_in *sin, char *string, php_socket *php_soc
99
106
#else
100
107
PHP_SOCKET_ERROR (php_sock , "Host lookup failed" , (-10000 - h_errno ));
101
108
#endif
102
- return 0 ;
109
+ return FAILURE ;
103
110
}
104
111
if (host_entry -> h_addrtype != AF_INET ) {
105
112
php_error_docref (NULL , E_WARNING , "Host lookup failed: Non AF_INET domain returned on AF_INET socket" );
106
- return 0 ;
113
+ return FAILURE ;
107
114
}
108
115
memcpy (& (sin -> sin_addr .s_addr ), host_entry -> h_addr_list [0 ], host_entry -> h_length );
109
116
}
110
117
111
- return 1 ;
118
+ return SUCCESS ;
112
119
}
113
120
/* }}} */
114
121
115
122
/* Sets addr by hostname or by ip in string form (AF_INET or AF_INET6,
116
123
* depending on the socket) */
117
- int php_set_inet46_addr (php_sockaddr_storage * ss , socklen_t * ss_len , char * string , php_socket * php_sock ) /* {{{ */
124
+ zend_result php_set_inet46_addr (php_sockaddr_storage * ss , socklen_t * ss_len , char * string , php_socket * php_sock ) /* {{{ */
118
125
{
119
126
if (php_sock -> type == AF_INET ) {
120
127
struct sockaddr_in t = {0 };
121
- if (php_set_inet_addr (& t , string , php_sock )) {
128
+ if (php_set_inet_addr (& t , string , php_sock ) == SUCCESS ) {
122
129
memcpy (ss , & t , sizeof t );
123
130
ss -> ss_family = AF_INET ;
124
131
* ss_len = sizeof (t );
125
- return 1 ;
132
+ return SUCCESS ;
126
133
}
127
134
}
128
135
#ifdef HAVE_IPV6
129
136
else if (php_sock -> type == AF_INET6 ) {
130
137
struct sockaddr_in6 t = {0 };
131
- if (php_set_inet6_addr (& t , string , php_sock )) {
138
+ if (php_set_inet6_addr (& t , string , php_sock ) == SUCCESS ) {
132
139
memcpy (ss , & t , sizeof t );
133
140
ss -> ss_family = AF_INET6 ;
134
141
* ss_len = sizeof (t );
135
- return 1 ;
142
+ return SUCCESS ;
136
143
}
137
144
}
138
145
#endif
139
146
else {
140
147
php_error_docref (NULL , E_WARNING ,
141
148
"IP address used in the context of an unexpected type of socket" );
142
149
}
143
- return 0 ;
150
+ return FAILURE ;
144
151
}
0 commit comments