Skip to content

Commit 9eb8684

Browse files
committed
Promote warnings to Errors in sockets's extension.
1 parent 7352213 commit 9eb8684

21 files changed

+315
-240
lines changed

ext/sockets/conversions.c

Lines changed: 113 additions & 58 deletions
Large diffs are not rendered by default.

ext/sockets/multicast.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,12 @@ static int php_get_if_index_from_zval(zval *val, unsigned *out)
8787

8888
if (Z_TYPE_P(val) == IS_LONG) {
8989
if (Z_LVAL_P(val) < 0 || (zend_ulong)Z_LVAL_P(val) > UINT_MAX) {
90-
php_error_docref(NULL, E_WARNING,
91-
"The interface index cannot be negative or larger than %u;"
92-
" given " ZEND_LONG_FMT, UINT_MAX, Z_LVAL_P(val));
93-
ret = FAILURE;
94-
} else {
95-
*out = Z_LVAL_P(val);
96-
ret = SUCCESS;
90+
zend_value_error("The interface index cannot be negative or larger than %u; given " ZEND_LONG_FMT,
91+
UINT_MAX, Z_LVAL_P(val));
92+
return FAILURE;
9793
}
94+
*out = Z_LVAL_P(val);
95+
ret = SUCCESS;
9896
} else {
9997
zend_string *tmp_str;
10098
zend_string *str = zval_get_tmp_string(val, &tmp_str);
@@ -127,7 +125,7 @@ static int php_get_address_from_array(const HashTable *ht, const char *key,
127125
zend_string *str, *tmp_str;
128126

129127
if ((val = zend_hash_str_find(ht, key, strlen(key))) == NULL) {
130-
php_error_docref(NULL, E_WARNING, "No key \"%s\" passed in optval", key);
128+
zend_value_error("No key \"%s\" passed in optval", key);
131129
return FAILURE;
132130
}
133131
str = zval_get_tmp_string(val, &tmp_str);
@@ -282,8 +280,7 @@ int php_do_setsockopt_ip_mcast(php_socket *php_sock,
282280
case IP_MULTICAST_TTL:
283281
convert_to_long_ex(arg4);
284282
if (Z_LVAL_P(arg4) < 0L || Z_LVAL_P(arg4) > 255L) {
285-
php_error_docref(NULL, E_WARNING,
286-
"Expected a value between 0 and 255");
283+
zend_value_error("Expected a value between 0 and 255");
287284
return FAILURE;
288285
}
289286
ipv4_mcast_ttl_lback = (unsigned char) Z_LVAL_P(arg4);
@@ -347,8 +344,7 @@ int php_do_setsockopt_ipv6_mcast(php_socket *php_sock,
347344
case IPV6_MULTICAST_HOPS:
348345
convert_to_long_ex(arg4);
349346
if (Z_LVAL_P(arg4) < -1L || Z_LVAL_P(arg4) > 255L) {
350-
php_error_docref(NULL, E_WARNING,
351-
"Expected a value between -1 and 255");
347+
zend_value_error("Expected a value between -1 and 255");
352348
return FAILURE;
353349
}
354350
ov = (int) Z_LVAL_P(arg4);
@@ -496,8 +492,7 @@ static int _php_mcast_join_leave(
496492
}
497493
#endif
498494
else {
499-
php_error_docref(NULL, E_WARNING,
500-
"Option %s is inapplicable to this socket type",
495+
zend_value_error("Option %s is inapplicable to this socket type",
501496
join ? "MCAST_JOIN_GROUP" : "MCAST_LEAVE_GROUP");
502497
return -2;
503498
}

ext/sockets/sendrecvmsg.c

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,11 @@ inline ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags)
6666
}
6767
#endif
6868

69-
#define LONG_CHECK_VALID_INT(l) \
69+
#define LONG_CHECK_VALID_INT(l, arg_pos) \
7070
do { \
7171
if ((l) < INT_MIN && (l) > INT_MAX) { \
72-
php_error_docref(NULL, E_WARNING, "The value " ZEND_LONG_FMT " does not fit inside " \
73-
"the boundaries of a native integer", (l)); \
74-
return; \
72+
zend_argument_value_error((arg_pos), "must fit inside the boundaries of a native integer"); \
73+
RETURN_THROWS(); \
7574
} \
7675
} while (0)
7776

@@ -177,7 +176,7 @@ PHP_FUNCTION(socket_sendmsg)
177176
RETURN_THROWS();
178177
}
179178

180-
LONG_CHECK_VALID_INT(flags);
179+
LONG_CHECK_VALID_INT(flags, 3);
181180

182181
if ((php_sock = (php_socket *)zend_fetch_resource(Z_RES_P(zsocket),
183182
php_sockets_le_socket_name, php_sockets_le_socket())) == NULL) {
@@ -222,7 +221,7 @@ PHP_FUNCTION(socket_recvmsg)
222221
RETURN_THROWS();
223222
}
224223

225-
LONG_CHECK_VALID_INT(flags);
224+
LONG_CHECK_VALID_INT(flags, 3);
226225

227226
if ((php_sock = (php_socket *)zend_fetch_resource(Z_RES_P(zsocket),
228227
php_sockets_le_socket_name, php_sockets_le_socket())) == NULL) {
@@ -285,21 +284,20 @@ PHP_FUNCTION(socket_cmsg_space)
285284
RETURN_THROWS();
286285
}
287286

288-
LONG_CHECK_VALID_INT(level);
289-
LONG_CHECK_VALID_INT(type);
290-
LONG_CHECK_VALID_INT(n);
287+
LONG_CHECK_VALID_INT(level, 1);
288+
LONG_CHECK_VALID_INT(type, 2);
289+
LONG_CHECK_VALID_INT(n, 3);
291290

292291
if (n < 0) {
293-
php_error_docref(NULL, E_WARNING, "The third argument "
294-
"cannot be negative");
295-
return;
292+
zend_argument_value_error(3, "must be greater or equal than 0");
293+
RETURN_THROWS();
296294
}
297295

298296
entry = get_ancillary_reg_entry(level, type);
299297
if (entry == NULL) {
300-
php_error_docref(NULL, E_WARNING, "The pair level " ZEND_LONG_FMT "/type " ZEND_LONG_FMT " is "
301-
"not supported by PHP", level, type);
302-
return;
298+
zend_value_error("Pair level " ZEND_LONG_FMT " and/or type " ZEND_LONG_FMT " is not supported",
299+
level, type);
300+
RETURN_THROWS();
303301
}
304302

305303
if (entry->var_el_size > 0) {
@@ -310,9 +308,8 @@ PHP_FUNCTION(socket_cmsg_space)
310308
if (n > n_max /* zend_long overflow */
311309
|| total_size > ZEND_LONG_MAX
312310
|| total_size < size /* align overflow */) {
313-
php_error_docref(NULL, E_WARNING, "The value for the "
314-
"third argument (" ZEND_LONG_FMT ") is too large", n);
315-
return;
311+
zend_argument_value_error(3, "is too large");
312+
RETURN_THROWS();
316313
}
317314
}
318315

0 commit comments

Comments
 (0)