Skip to content

Promote warnings to Errors in sockets's extension. #5075

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions ext/sockets/multicast.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,11 @@ static int php_get_if_index_from_zval(zval *val, unsigned *out)

if (Z_TYPE_P(val) == IS_LONG) {
if (Z_LVAL_P(val) < 0 || (zend_ulong)Z_LVAL_P(val) > UINT_MAX) {
php_error_docref(NULL, E_WARNING,
"The interface index cannot be negative or larger than %u;"
" given " ZEND_LONG_FMT, UINT_MAX, Z_LVAL_P(val));
ret = FAILURE;
} else {
*out = Z_LVAL_P(val);
ret = SUCCESS;
zend_value_error("Index must be between 0 and %u", UINT_MAX);
return FAILURE;
}
*out = Z_LVAL_P(val);
ret = SUCCESS;
} else {
zend_string *tmp_str;
zend_string *str = zval_get_tmp_string(val, &tmp_str);
Expand Down Expand Up @@ -127,7 +124,7 @@ static int php_get_address_from_array(const HashTable *ht, const char *key,
zend_string *str, *tmp_str;

if ((val = zend_hash_str_find(ht, key, strlen(key))) == NULL) {
php_error_docref(NULL, E_WARNING, "No key \"%s\" passed in optval", key);
zend_value_error("No key \"%s\" passed in optval", key);
return FAILURE;
}
str = zval_get_tmp_string(val, &tmp_str);
Expand Down Expand Up @@ -282,8 +279,7 @@ int php_do_setsockopt_ip_mcast(php_socket *php_sock,
case IP_MULTICAST_TTL:
convert_to_long_ex(arg4);
if (Z_LVAL_P(arg4) < 0L || Z_LVAL_P(arg4) > 255L) {
php_error_docref(NULL, E_WARNING,
"Expected a value between 0 and 255");
zend_argument_value_error(4, "must be between 0 and 255");
return FAILURE;
}
ipv4_mcast_ttl_lback = (unsigned char) Z_LVAL_P(arg4);
Expand Down Expand Up @@ -347,8 +343,7 @@ int php_do_setsockopt_ipv6_mcast(php_socket *php_sock,
case IPV6_MULTICAST_HOPS:
convert_to_long_ex(arg4);
if (Z_LVAL_P(arg4) < -1L || Z_LVAL_P(arg4) > 255L) {
php_error_docref(NULL, E_WARNING,
"Expected a value between -1 and 255");
zend_argument_value_error(4, "must be between -1 and 255");
return FAILURE;
}
ov = (int) Z_LVAL_P(arg4);
Expand Down Expand Up @@ -496,8 +491,7 @@ static int _php_mcast_join_leave(
}
#endif
else {
php_error_docref(NULL, E_WARNING,
"Option %s is inapplicable to this socket type",
zend_value_error("Option %s is inapplicable to this socket type",
join ? "MCAST_JOIN_GROUP" : "MCAST_LEAVE_GROUP");
return -2;
}
Expand Down
33 changes: 15 additions & 18 deletions ext/sockets/sendrecvmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,11 @@ inline ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags)
}
#endif

#define LONG_CHECK_VALID_INT(l) \
#define LONG_CHECK_VALID_INT(l, arg_pos) \
do { \
if ((l) < INT_MIN && (l) > INT_MAX) { \
php_error_docref(NULL, E_WARNING, "The value " ZEND_LONG_FMT " does not fit inside " \
"the boundaries of a native integer", (l)); \
return; \
zend_argument_value_error((arg_pos), "must be between %d and %d", INT_MIN, INT_MAX); \
RETURN_THROWS(); \
} \
} while (0)

Expand Down Expand Up @@ -177,7 +176,7 @@ PHP_FUNCTION(socket_sendmsg)
RETURN_THROWS();
}

LONG_CHECK_VALID_INT(flags);
LONG_CHECK_VALID_INT(flags, 3);

if ((php_sock = (php_socket *)zend_fetch_resource(Z_RES_P(zsocket),
php_sockets_le_socket_name, php_sockets_le_socket())) == NULL) {
Expand Down Expand Up @@ -222,7 +221,7 @@ PHP_FUNCTION(socket_recvmsg)
RETURN_THROWS();
}

LONG_CHECK_VALID_INT(flags);
LONG_CHECK_VALID_INT(flags, 3);

if ((php_sock = (php_socket *)zend_fetch_resource(Z_RES_P(zsocket),
php_sockets_le_socket_name, php_sockets_le_socket())) == NULL) {
Expand Down Expand Up @@ -285,21 +284,20 @@ PHP_FUNCTION(socket_cmsg_space)
RETURN_THROWS();
}

LONG_CHECK_VALID_INT(level);
LONG_CHECK_VALID_INT(type);
LONG_CHECK_VALID_INT(n);
LONG_CHECK_VALID_INT(level, 1);
LONG_CHECK_VALID_INT(type, 2);
LONG_CHECK_VALID_INT(n, 3);

if (n < 0) {
php_error_docref(NULL, E_WARNING, "The third argument "
"cannot be negative");
return;
zend_argument_value_error(3, "must be greater or equal than 0");
RETURN_THROWS();
}

entry = get_ancillary_reg_entry(level, type);
if (entry == NULL) {
php_error_docref(NULL, E_WARNING, "The pair level " ZEND_LONG_FMT "/type " ZEND_LONG_FMT " is "
"not supported by PHP", level, type);
return;
zend_value_error("Pair level " ZEND_LONG_FMT " and/or type " ZEND_LONG_FMT " is not supported",
level, type);
RETURN_THROWS();
}

if (entry->var_el_size > 0) {
Expand All @@ -310,9 +308,8 @@ PHP_FUNCTION(socket_cmsg_space)
if (n > n_max /* zend_long overflow */
|| total_size > ZEND_LONG_MAX
|| total_size < size /* align overflow */) {
php_error_docref(NULL, E_WARNING, "The value for the "
"third argument (" ZEND_LONG_FMT ") is too large", n);
return;
zend_argument_value_error(3, "is too large");
RETURN_THROWS();
}
}

Expand Down
Loading