diff --git a/NEWS b/NEWS index 181f254923790..44780f84d7454 100644 --- a/NEWS +++ b/NEWS @@ -63,6 +63,9 @@ PHP NEWS . Added pg_close_stmt to close a prepared statement while allowing its name to be reused. (David Carlier) . Added Iterable support for pgsql_copy_from. (David Carlier) + . pg_connect checks if connection_string contains any null byte, + pg_close_stmt check if the statement contains any null byte. + (David Carlier) - POSIX: . Added POSIX_SC_OPEN_MAX constant to get the number of file descriptors @@ -83,10 +86,19 @@ PHP NEWS or a TypeError if read_and_close value is not compatible with int. (David Carlier) +- SNMP: + . snmpget, snmpset, snmp_get2, snmp_set2, snmp_get3, snmp_set3 and + SNMP::__construct() throw an exception on invalid hostname, community + timeout and retries arguments. (David Carlier) + - SOAP: . Fixed bug #49169 (SoapServer calls wrong function, although "SOAP action" header is correct). (nielsdos) +- Sodium: + . Fix overall theorical overflows on zend_string buffer allocations. + (David Carlier/nielsdos) + - Sockets: . Added IPPROTO_ICMP/IPPROTO_ICMPV6 to create raw socket for ICMP usage. (David Carlier) diff --git a/UPGRADING b/UPGRADING index 086fb975d05df..805d2f62440b7 100644 --- a/UPGRADING +++ b/UPGRADING @@ -125,6 +125,10 @@ PHP 8.5 UPGRADE NOTES - PGSQL: . pg_copy_from also supports inputs as Iterable. + . pg_connect checks if the connection_string argument contains + any null byte. + . pg_close_stmt checks if the statement_name argument contains + any null byte. - POSIX: . posix_ttyname sets last_error to EBADF when encountering @@ -140,6 +144,13 @@ PHP 8.5 UPGRADE NOTES a TypeError if read_on_close value is not a valid type compatible with int. +- SNMP: + . snmpget, snmpset, snmp_get2, snmp_set2, snmp_get3, snmp_set3 + and SNMP::__construct() throw a ValueError when the hostname + is too large, contains any null byte or if the port is given + when negative or greater than 65535, timeout and retries values + are lower than -1 or too large. + - Sockets: . socket_create_listen, socket_bind and socket_sendto throw a ValueError if the port is lower than 0 or greater than 65535, diff --git a/Zend/zend_bitset.h b/Zend/zend_bitset.h index a42b35712f4e6..d990b6a2a871e 100644 --- a/Zend/zend_bitset.h +++ b/Zend/zend_bitset.h @@ -60,7 +60,6 @@ ZEND_ATTRIBUTE_CONST static zend_always_inline int zend_ulong_ntz(zend_ulong num #else if (!BitScanForward(&index, num)) { #endif - /* undefined behavior */ return SIZEOF_ZEND_LONG * 8; } @@ -98,7 +97,6 @@ ZEND_ATTRIBUTE_CONST static zend_always_inline int zend_ulong_nlz(zend_ulong num #else if (!BitScanReverse(&index, num)) { #endif - /* undefined behavior */ return SIZEOF_ZEND_LONG * 8; } diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index 4854fdbfd1a2b..b1a1dfb49a7ac 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -665,7 +665,7 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) PGresult *pg_result; ZEND_PARSE_PARAMETERS_START(1, 2) - Z_PARAM_STRING(connstring, connstring_len) + Z_PARAM_PATH(connstring, connstring_len) Z_PARAM_OPTIONAL Z_PARAM_LONG(connect_type) ZEND_PARSE_PARAMETERS_END(); @@ -1123,7 +1123,7 @@ PHP_FUNCTION(pg_query) zval *pgsql_link = NULL; char *query; size_t query_len; - int leftover = 0; + bool leftover = false; pgsql_link_handle *link; PGconn *pgsql; PGresult *pgsql_result; @@ -1157,7 +1157,7 @@ PHP_FUNCTION(pg_query) } while ((pgsql_result = PQgetResult(pgsql))) { PQclear(pgsql_result); - leftover = 1; + leftover = true; } if (leftover) { php_error_docref(NULL, E_NOTICE, "Found results on this connection. Use pg_get_result() to get these results first"); @@ -1220,7 +1220,7 @@ PHP_FUNCTION(pg_query_params) zval *pv_param_arr, *tmp; char *query; size_t query_len; - int leftover = 0; + bool leftover = false; int num_params = 0; char **params = NULL; pgsql_link_handle *link; @@ -1259,7 +1259,7 @@ PHP_FUNCTION(pg_query_params) } while ((pgsql_result = PQgetResult(pgsql))) { PQclear(pgsql_result); - leftover = 1; + leftover = true; } if (leftover) { php_error_docref(NULL, E_NOTICE, "Found results on this connection. Use pg_get_result() to get these results first"); @@ -1335,7 +1335,7 @@ PHP_FUNCTION(pg_prepare) zval *pgsql_link = NULL; char *query, *stmtname; size_t query_len, stmtname_len; - int leftover = 0; + bool leftover = false; PGconn *pgsql; pgsql_link_handle *link; PGresult *pgsql_result; @@ -1372,7 +1372,7 @@ PHP_FUNCTION(pg_prepare) } while ((pgsql_result = PQgetResult(pgsql))) { PQclear(pgsql_result); - leftover = 1; + leftover = true; } if (leftover) { php_error_docref(NULL, E_NOTICE, "Found results on this connection. Use pg_get_result() to get these results first"); @@ -1422,7 +1422,7 @@ PHP_FUNCTION(pg_execute) zval *pv_param_arr, *tmp; char *stmtname; size_t stmtname_len; - int leftover = 0; + bool leftover = false; int num_params = 0; char **params = NULL; PGconn *pgsql; @@ -1461,7 +1461,7 @@ PHP_FUNCTION(pg_execute) } while ((pgsql_result = PQgetResult(pgsql))) { PQclear(pgsql_result); - leftover = 1; + leftover = true; } if (leftover) { php_error_docref(NULL, E_NOTICE, "Found results on this connection. Use pg_get_result() to get these results first"); @@ -1690,7 +1690,7 @@ PHP_FUNCTION(pg_field_table) zval *result; pgsql_result_handle *pg_result; zend_long fnum = -1; - bool return_oid = 0; + bool return_oid = false; ZEND_PARSE_PARAMETERS_START(2, 3) Z_PARAM_OBJECT_OF_CLASS(result, pgsql_result_ce) @@ -2770,14 +2770,14 @@ PHP_FUNCTION(pg_lo_write) zval *pgsql_id; zend_string *str; zend_long z_len; - bool z_len_is_null = 1; + bool z_len_is_null = true; size_t nbytes; size_t len; pgLofp *pgsql; ZEND_PARSE_PARAMETERS_START(2, 3) Z_PARAM_OBJECT_OF_CLASS(pgsql_id, pgsql_lob_ce) - Z_PARAM_STR(str) + Z_PARAM_PATH_STR(str) Z_PARAM_OPTIONAL Z_PARAM_LONG_OR_NULL(z_len, z_len_is_null) ZEND_PARSE_PARAMETERS_END(); @@ -3346,7 +3346,7 @@ PHP_FUNCTION(pg_copy_to) switch (status) { case PGRES_COPY_OUT: if (pgsql_result) { - int copydone = 0; + bool copydone = false; PQclear(pgsql_result); array_init(return_value); @@ -3355,7 +3355,7 @@ PHP_FUNCTION(pg_copy_to) int ret = PQgetCopyData(pgsql, &csv, 0); switch (ret) { case -1: - copydone = 1; + copydone = true; break; case 0: case -2: @@ -4654,7 +4654,7 @@ PHP_FUNCTION(pg_meta_data) zval *pgsql_link; pgsql_link_handle *link; zend_string *table_name; - bool extended=0; + bool extended = false; PGconn *pgsql; ZEND_PARSE_PARAMETERS_START(2, 3) @@ -4832,7 +4832,7 @@ static zend_string *php_pgsql_add_quotes(zend_string *src) /* if new_value is string "NULL" and field has default value, remove element to use default value */ \ if (!(opt & PGSQL_CONV_IGNORE_DEFAULT) && Z_TYPE_P(has_default) == IS_TRUE) { \ zval_ptr_dtor(&new_val); \ - skip_field = 1; \ + skip_field = true; \ } \ /* raise error if it's not null and cannot be ignored */ \ else if (!(opt & PGSQL_CONV_IGNORE_NOT_NULL) && Z_TYPE_P(not_null) == IS_TRUE) { \ @@ -4848,7 +4848,8 @@ PHP_PGSQL_API zend_result php_pgsql_convert(PGconn *pg_link, const zend_string * { zend_string *field = NULL; zval meta, *def, *type, *not_null, *has_default, *is_enum, *val, new_val; - int err = 0, skip_field; + int err = 0; + bool skip_field; php_pgsql_data_type data_type; ZEND_ASSERT(pg_link != NULL); @@ -4867,7 +4868,7 @@ PHP_PGSQL_API zend_result php_pgsql_convert(PGconn *pg_link, const zend_string * } ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(values), field, val) { - skip_field = 0; + skip_field = false; ZVAL_DEREF(val); ZVAL_NULL(&new_val); @@ -6324,11 +6325,11 @@ PHP_FUNCTION(pg_close_stmt) ZEND_PARSE_PARAMETERS_START(2, 2) Z_PARAM_OBJECT_OF_CLASS(pgsql_link, pgsql_link_ce) - Z_PARAM_STR(stmt) + Z_PARAM_PATH_STR(stmt) ZEND_PARSE_PARAMETERS_END(); if (ZSTR_LEN(stmt) == 0) { - zend_argument_value_error(2, "cannot be empty"); + zend_argument_must_not_be_empty_error(2); RETURN_THROWS(); } diff --git a/ext/pgsql/tests/05large_object.phpt b/ext/pgsql/tests/05large_object.phpt index a785b76a572d3..957f2dffa8ea7 100644 --- a/ext/pgsql/tests/05large_object.phpt +++ b/ext/pgsql/tests/05large_object.phpt @@ -17,6 +17,11 @@ $oid = pg_lo_create ($db); if (!$oid) echo ("pg_lo_create() error\n"); $handle = pg_lo_open ($db, $oid, "w"); if (!$handle) echo ("pg_lo_open() error\n"); +try { + pg_lo_write ($handle, "large\0object data"); +} catch (\ValueError $e) { + echo $e->getMessage(), PHP_EOL; +} pg_lo_write ($handle, "large object data"); pg_lo_close ($handle); pg_exec ($db, "COMMIT"); @@ -105,6 +110,7 @@ echo "OK"; ?> --EXPECTF-- create/write/close LO +pg_lo_write(): Argument #2 ($data) must not contain any null bytes open/read/tell/seek/close LO string(5) "large" int(5) diff --git a/ext/pgsql/tests/pg_close_stmt.phpt b/ext/pgsql/tests/pg_close_stmt.phpt index e93108c1e7a22..206ffeb0eea39 100644 --- a/ext/pgsql/tests/pg_close_stmt.phpt +++ b/ext/pgsql/tests/pg_close_stmt.phpt @@ -18,6 +18,11 @@ $db = pg_connect($conn_str); $res = pg_prepare($db, 'test', $query); $res = pg_execute($db, 'test', $params_null); +try { + pg_close_stmt($db, ''); +} catch (\ValueError $e) { + echo $e->getMessage(), PHP_EOL; +} $res = pg_close_stmt($db, 'test'); var_dump($res !== false); var_dump(pg_result_status($res) === PGSQL_COMMAND_OK); @@ -29,5 +34,6 @@ pg_close($db); ?> --EXPECT-- +pg_close_stmt(): Argument #2 ($statement_name) must not be empty bool(true) bool(true) diff --git a/ext/snmp/snmp.c b/ext/snmp/snmp.c index 91b530f3b39d7..abee491720851 100644 --- a/ext/snmp/snmp.c +++ b/ext/snmp/snmp.c @@ -153,7 +153,7 @@ static PHP_GINIT_FUNCTION(snmp) } \ } -static void netsnmp_session_free(php_snmp_session **session) /* {{{ */ +static void snmp_session_free(php_snmp_session **session) /* {{{ */ { if (*session) { PHP_SNMP_SESSION_FREE(peername); @@ -174,7 +174,7 @@ static void php_snmp_object_free_storage(zend_object *object) /* {{{ */ return; } - netsnmp_session_free(&(intern->session)); + snmp_session_free(&(intern->session)); zend_object_std_dtor(&intern->zo); } @@ -829,10 +829,10 @@ static bool php_snmp_parse_oid( } /* }}} */ -/* {{{ netsnmp_session_init - allocates memory for session and session->peername, caller should free it manually using netsnmp_session_free() and efree() +/* {{{ snmp_session_init + allocates memory for session and session->peername, caller should free it manually using snmp_session_free() and efree() */ -static bool netsnmp_session_init(php_snmp_session **session_p, int version, zend_string *hostname, zend_string *community, int timeout, int retries) +static bool snmp_session_init(php_snmp_session **session_p, int version, zend_string *hostname, zend_string *community, zend_long timeout, zend_long retries, int timeout_argument_offset) { php_snmp_session *session; char *pptr, *host_ptr; @@ -840,8 +840,47 @@ static bool netsnmp_session_init(php_snmp_session **session_p, int version, zend int n; struct sockaddr **psal; struct sockaddr **res; + + *session_p = 0; + + ZEND_ASSERT(hostname != NULL); + ZEND_ASSERT(community != NULL); + + if (zend_str_has_nul_byte(hostname)) { + zend_argument_value_error(2, "must not contain any null bytes"); + return false; + } + + if (ZSTR_LEN(hostname) >= MAX_NAME_LEN) { + zend_argument_value_error(2, "length must be lower than %d", MAX_NAME_LEN); + return false; + } + + if (zend_str_has_nul_byte(community)) { + zend_argument_value_error(3, "must not contain any null bytes"); + return false; + } + + if (ZSTR_LEN(community) == 0) { + zend_argument_must_not_be_empty_error(3); + return false; + } + + if (timeout_argument_offset != -1) { + if (timeout < -1 || timeout > LONG_MAX) { + zend_argument_value_error(timeout_argument_offset, "must be between -1 and %ld", LONG_MAX); + return false; + } + + if (retries < -1 || retries > INT_MAX) { + zend_argument_value_error(timeout_argument_offset + 1, "must be between -1 and %d", INT_MAX); + return false; + } + } + // TODO: Do not strip and re-add the port in peername? - unsigned remote_port = SNMP_PORT; + unsigned short remote_port = SNMP_PORT; + int tmp_port; *session_p = (php_snmp_session *)emalloc(sizeof(php_snmp_session)); session = *session_p; @@ -849,11 +888,11 @@ static bool netsnmp_session_init(php_snmp_session **session_p, int version, zend snmp_sess_init(session); - session->version = version; + session->version = (long)version; session->peername = emalloc(MAX_NAME_LEN); /* we copy original hostname for further processing */ - strlcpy(session->peername, ZSTR_VAL(hostname), MAX_NAME_LEN); + memcpy(session->peername, ZSTR_VAL(hostname), ZSTR_LEN(hostname) + 1); host_ptr = session->peername; /* Reading the hostname and its optional non-default port number */ @@ -862,7 +901,13 @@ static bool netsnmp_session_init(php_snmp_session **session_p, int version, zend host_ptr++; if ((pptr = strchr(host_ptr, ']'))) { if (pptr[1] == ':') { - remote_port = atoi(pptr + 2); + char *pport = pptr + 2; + tmp_port = atoi(pport); + if (tmp_port < 0 || tmp_port > USHRT_MAX) { + zend_argument_value_error(2, "remote port must be between 0 and %u", USHRT_MAX); + return false; + } + remote_port = (unsigned short)tmp_port; } *pptr = '\0'; } else { @@ -871,7 +916,13 @@ static bool netsnmp_session_init(php_snmp_session **session_p, int version, zend } } else { /* IPv4 address */ if ((pptr = strchr(host_ptr, ':'))) { - remote_port = atoi(pptr + 1); + char *pport = pptr + 1; + tmp_port = atoi(pport); + if (tmp_port < 0 || tmp_port > USHRT_MAX) { + zend_argument_value_error(2, "remote port must be between 0 and %u", USHRT_MAX); + return false; + } + remote_port = (unsigned short)tmp_port; *pptr = '\0'; } } @@ -920,7 +971,7 @@ static bool netsnmp_session_init(php_snmp_session **session_p, int version, zend if (remote_port != SNMP_PORT) { size_t peername_length = strlen(session->peername); pptr = session->peername + peername_length; - snprintf(pptr, MAX_NAME_LEN - peername_length, ":%d", remote_port); + snprintf(pptr, MAX_NAME_LEN - peername_length, ":%u", remote_port); } php_network_freeaddresses(psal); @@ -935,14 +986,14 @@ static bool netsnmp_session_init(php_snmp_session **session_p, int version, zend session->community_len = ZSTR_LEN(community); } - session->retries = retries; - session->timeout = timeout; + session->retries = (int)retries; + session->timeout = (long)timeout; return true; } /* }}} */ /* {{{ Set the security level in the snmpv3 session */ -static bool netsnmp_session_set_sec_level(struct snmp_session *s, zend_string *level) +static bool snmp_session_set_sec_level(struct snmp_session *s, zend_string *level) { if (zend_string_equals_literal_ci(level, "noAuthNoPriv") || zend_string_equals_literal_ci(level, "nanp")) { s->securityLevel = SNMP_SEC_LEVEL_NOAUTH; @@ -959,7 +1010,7 @@ static bool netsnmp_session_set_sec_level(struct snmp_session *s, zend_string *l /* }}} */ /* {{{ Set the authentication protocol in the snmpv3 session */ -static bool netsnmp_session_set_auth_protocol(struct snmp_session *s, zend_string *prot) +static bool snmp_session_set_auth_protocol(struct snmp_session *s, zend_string *prot) { #ifndef DISABLE_MD5 if (zend_string_equals_literal_ci(prot, "MD5")) { @@ -1011,7 +1062,7 @@ static bool netsnmp_session_set_auth_protocol(struct snmp_session *s, zend_strin /* }}} */ /* {{{ Set the security protocol in the snmpv3 session */ -static bool netsnmp_session_set_sec_protocol(struct snmp_session *s, zend_string *prot) +static bool snmp_session_set_sec_protocol(struct snmp_session *s, zend_string *prot) { #ifndef NETSNMP_DISABLE_DES if (zend_string_equals_literal_ci(prot, "DES")) { @@ -1048,7 +1099,7 @@ static bool netsnmp_session_set_sec_protocol(struct snmp_session *s, zend_string /* }}} */ /* {{{ Make key from pass phrase in the snmpv3 session */ -static bool netsnmp_session_gen_auth_key(struct snmp_session *s, zend_string *pass) +static bool snmp_session_gen_auth_key(struct snmp_session *s, zend_string *pass) { int snmp_errno; s->securityAuthKeyLen = USM_AUTH_KU_LEN; @@ -1063,7 +1114,7 @@ static bool netsnmp_session_gen_auth_key(struct snmp_session *s, zend_string *pa /* }}} */ /* {{{ Make key from pass phrase in the snmpv3 session */ -static bool netsnmp_session_gen_sec_key(struct snmp_session *s, zend_string *pass) +static bool snmp_session_gen_sec_key(struct snmp_session *s, zend_string *pass) { int snmp_errno; @@ -1079,7 +1130,7 @@ static bool netsnmp_session_gen_sec_key(struct snmp_session *s, zend_string *pas /* }}} */ /* {{{ Set context Engine Id in the snmpv3 session */ -static bool netsnmp_session_set_contextEngineID(struct snmp_session *s, zend_string * contextEngineID) +static bool snmp_session_set_contextEngineID(struct snmp_session *s, zend_string * contextEngineID) { size_t ebuf_len = 32, eout_len = 0; uint8_t *ebuf = (uint8_t *) emalloc(ebuf_len); @@ -1102,13 +1153,13 @@ static bool netsnmp_session_set_contextEngineID(struct snmp_session *s, zend_str /* }}} */ /* {{{ Set all snmpv3-related security options */ -static bool netsnmp_session_set_security(struct snmp_session *session, zend_string *sec_level, +static bool snmp_session_set_security(struct snmp_session *session, zend_string *sec_level, zend_string *auth_protocol, zend_string *auth_passphrase, zend_string *priv_protocol, zend_string *priv_passphrase, zend_string *contextName, zend_string *contextEngineID) { /* Setting the security level. */ - if (!netsnmp_session_set_sec_level(session, sec_level)) { + if (!snmp_session_set_sec_level(session, sec_level)) { /* ValueError already generated, just bail out */ return false; } @@ -1116,26 +1167,26 @@ static bool netsnmp_session_set_security(struct snmp_session *session, zend_stri if (session->securityLevel == SNMP_SEC_LEVEL_AUTHNOPRIV || session->securityLevel == SNMP_SEC_LEVEL_AUTHPRIV) { /* Setting the authentication protocol. */ - if (!netsnmp_session_set_auth_protocol(session, auth_protocol)) { + if (!snmp_session_set_auth_protocol(session, auth_protocol)) { /* ValueError already generated, just bail out */ return false; } /* Setting the authentication passphrase. */ - if (!netsnmp_session_gen_auth_key(session, auth_passphrase)) { + if (!snmp_session_gen_auth_key(session, auth_passphrase)) { /* Warning message sent already, just bail out */ return false; } if (session->securityLevel == SNMP_SEC_LEVEL_AUTHPRIV) { /* Setting the security protocol. */ - if (!netsnmp_session_set_sec_protocol(session, priv_protocol)) { + if (!snmp_session_set_sec_protocol(session, priv_protocol)) { /* ValueError already generated, just bail out */ return false; } /* Setting the security protocol passphrase. */ - if (!netsnmp_session_gen_sec_key(session, priv_passphrase)) { + if (!snmp_session_gen_sec_key(session, priv_passphrase)) { /* Warning message sent already, just bail out */ return false; } @@ -1149,7 +1200,7 @@ static bool netsnmp_session_set_security(struct snmp_session *session, zend_stri } /* Setting contextEngineIS if specified */ - if (contextEngineID && ZSTR_LEN(contextEngineID) && !netsnmp_session_set_contextEngineID(session, contextEngineID)) { + if (contextEngineID && ZSTR_LEN(contextEngineID) && !snmp_session_set_contextEngineID(session, contextEngineID)) { /* Warning message sent already, just bail out */ return false; } @@ -1176,6 +1227,7 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version) struct objid_query objid_query; php_snmp_session *session; int session_less_mode = (getThis() == NULL); + int timeout_argument_offset = -1; php_snmp_object *snmp_object; php_snmp_object glob_snmp_object; @@ -1202,6 +1254,8 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version) Z_PARAM_LONG(timeout) Z_PARAM_LONG(retries) ZEND_PARSE_PARAMETERS_END(); + + timeout_argument_offset = 10; } else { /* SNMP_CMD_GET * SNMP_CMD_GETNEXT @@ -1220,6 +1274,8 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version) Z_PARAM_LONG(timeout) Z_PARAM_LONG(retries) ZEND_PARSE_PARAMETERS_END(); + + timeout_argument_offset = 9; } } else { if (st & SNMP_CMD_SET) { @@ -1233,6 +1289,8 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version) Z_PARAM_LONG(timeout) Z_PARAM_LONG(retries) ZEND_PARSE_PARAMETERS_END(); + + timeout_argument_offset = 6; } else { /* SNMP_CMD_GET * SNMP_CMD_GETNEXT @@ -1246,6 +1304,8 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version) Z_PARAM_LONG(timeout) Z_PARAM_LONG(retries) ZEND_PARSE_PARAMETERS_END(); + + timeout_argument_offset = 4; } } } else { @@ -1289,14 +1349,14 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version) } if (session_less_mode) { - if (!netsnmp_session_init(&session, version, a1, a2, timeout, retries)) { + if (!snmp_session_init(&session, version, a1, a2, timeout, retries, timeout_argument_offset)) { php_free_objid_query(&objid_query, oid_ht, value_ht, st); - netsnmp_session_free(&session); + snmp_session_free(&session); RETURN_FALSE; } - if (version == SNMP_VERSION_3 && !netsnmp_session_set_security(session, a3, a4, a5, a6, a7, NULL, NULL)) { + if (version == SNMP_VERSION_3 && !snmp_session_set_security(session, a3, a4, a5, a6, a7, NULL, NULL)) { php_free_objid_query(&objid_query, oid_ht, value_ht, st); - netsnmp_session_free(&session); + snmp_session_free(&session); /* Warning message sent already, just bail out */ RETURN_FALSE; } @@ -1335,7 +1395,7 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version) php_free_objid_query(&objid_query, oid_ht, value_ht, st); if (session_less_mode) { - netsnmp_session_free(&session); + snmp_session_free(&session); } else { netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_NUMERIC_ENUM, glob_snmp_object.enum_print); netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT, glob_snmp_object.quick_print); @@ -1590,10 +1650,10 @@ PHP_METHOD(SNMP, __construct) /* handle re-open of snmp session */ if (snmp_object->session) { - netsnmp_session_free(&(snmp_object->session)); + snmp_session_free(&(snmp_object->session)); } - if (!netsnmp_session_init(&(snmp_object->session), version, a1, a2, timeout, retries)) { + if (!snmp_session_init(&(snmp_object->session), version, a1, a2, timeout, retries, 4)) { return; } snmp_object->max_oids = 0; @@ -1618,7 +1678,7 @@ PHP_METHOD(SNMP, close) RETURN_THROWS(); } - netsnmp_session_free(&(snmp_object->session)); + snmp_session_free(&(snmp_object->session)); RETURN_TRUE; } @@ -1669,7 +1729,7 @@ PHP_METHOD(SNMP, setSecurity) RETURN_THROWS(); } - if (!netsnmp_session_set_security(snmp_object->session, a1, a2, a3, a4, a5, a6, a7)) { + if (!snmp_session_set_security(snmp_object->session, a1, a2, a3, a4, a5, a6, a7)) { /* Warning message sent already, just bail out */ RETURN_FALSE; } diff --git a/ext/snmp/tests/snmp_session_error.phpt b/ext/snmp/tests/snmp_session_error.phpt new file mode 100644 index 0000000000000..f5e46ee4d936c --- /dev/null +++ b/ext/snmp/tests/snmp_session_error.phpt @@ -0,0 +1,67 @@ +--TEST-- +SNMP::__construct checks +--CREDITS-- +Boris Lytochkin +--EXTENSIONS-- +snmp +--SKIPIF-- + +--FILE-- +getMessage(), PHP_EOL; +} +try { + new SNMP(SNMP::VERSION_1, "$hostname4:65536", $community, $timeout, $retries); +} catch (\ValueError $e) { + echo $e->getMessage(), PHP_EOL; +} +try { + new SNMP(SNMP::VERSION_1, "$longhostname:$port", $community, $timeout, $retries); +} catch (\ValueError $e) { + echo $e->getMessage(), PHP_EOL; +} +try { + new SNMP(SNMP::VERSION_1, "$hostname:$port", $community, PHP_INT_MIN, $retries); +} catch (\ValueError $e) { + echo $e->getMessage(), PHP_EOL; +} +try { + new SNMP(SNMP::VERSION_1, "$hostname:$port", $community, $timeout, PHP_INT_MAX); +} catch (\ValueError $e) { + echo $e->getMessage(), PHP_EOL; +} +try { + new SNMP(SNMP::VERSION_1, "\0$hostname:$port", $community, $timeout, $retries); +} catch (\ValueError $e) { + echo $e->getMessage(), PHP_EOL; +} +try { + new SNMP(SNMP::VERSION_1, "$hostname:$port", "", $timeout, $retries); +} catch (\ValueError $e) { + echo $e->getMessage(), PHP_EOL; +} +try { + new SNMP(SNMP::VERSION_1, "$hostname:$port", "\0$community", $timeout, $retries); +} catch (\ValueError $e) { + echo $e->getMessage(), PHP_EOL; +} +echo "OK"; +?> +--EXPECTF-- +SNMP::__construct(): Argument #2 ($hostname) remote port must be between 0 and 65535 +SNMP::__construct(): Argument #2 ($hostname) remote port must be between 0 and 65535 +SNMP::__construct(): Argument #2 ($hostname) length must be lower than 128 +SNMP::__construct(): Argument #4 ($timeout) must be between -1 and %d +SNMP::__construct(): Argument #5 ($retries) must be between -1 and %d +SNMP::__construct(): Argument #2 ($hostname) must not contain any null bytes +SNMP::__construct(): Argument #3 ($community) must not be empty +SNMP::__construct(): Argument #3 ($community) must not contain any null bytes +OK diff --git a/ext/sodium/libsodium.c b/ext/sodium/libsodium.c index 0dd6db0f3a863..2404f8aebb472 100644 --- a/ext/sodium/libsodium.c +++ b/ext/sodium/libsodium.c @@ -340,7 +340,7 @@ PHP_FUNCTION(sodium_crypto_secretbox) zend_argument_error(sodium_exception_ce, 3, "must be SODIUM_CRYPTO_SECRETBOX_KEYBYTES bytes long"); RETURN_THROWS(); } - if (SIZE_MAX - msg_len <= crypto_secretbox_MACBYTES) { + if (ZSTR_MAX_LEN - msg_len <= crypto_secretbox_MACBYTES) { zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); RETURN_THROWS(); } @@ -754,7 +754,7 @@ PHP_FUNCTION(sodium_crypto_box) } secretkey = keypair; publickey = keypair + crypto_box_SECRETKEYBYTES; - if (SIZE_MAX - msg_len <= crypto_box_MACBYTES) { + if (ZSTR_MAX_LEN - msg_len <= crypto_box_MACBYTES) { zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); RETURN_THROWS(); } @@ -833,7 +833,7 @@ PHP_FUNCTION(sodium_crypto_box_seal) zend_argument_error(sodium_exception_ce, 2, "must be SODIUM_CRYPTO_BOX_PUBLICKEYBYTES bytes long"); RETURN_THROWS(); } - if (SIZE_MAX - msg_len <= crypto_box_SEALBYTES) { + if (ZSTR_MAX_LEN - msg_len <= crypto_box_SEALBYTES) { zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); RETURN_THROWS(); } @@ -1068,7 +1068,7 @@ PHP_FUNCTION(sodium_crypto_sign) zend_argument_error(sodium_exception_ce, 2, "must be SODIUM_CRYPTO_SIGN_SECRETKEYBYTES bytes long"); RETURN_THROWS(); } - if (SIZE_MAX - msg_len <= crypto_sign_BYTES) { + if (ZSTR_MAX_LEN - msg_len <= crypto_sign_BYTES) { zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); RETURN_THROWS(); } @@ -1081,7 +1081,7 @@ PHP_FUNCTION(sodium_crypto_sign) zend_throw_exception(sodium_exception_ce, "internal error", 0); RETURN_THROWS(); } - if (msg_signed_real_len >= SIZE_MAX || msg_signed_real_len > msg_signed_len) { + if (msg_signed_real_len >= ZSTR_MAX_LEN || msg_signed_real_len > msg_signed_len) { zend_string_efree(msg_signed); zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); RETURN_THROWS(); @@ -1113,18 +1113,18 @@ PHP_FUNCTION(sodium_crypto_sign_open) RETURN_THROWS(); } msg_len = msg_signed_len; - if (msg_len >= SIZE_MAX) { + if (msg_len >= ZSTR_MAX_LEN) { zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); RETURN_THROWS(); } - msg = zend_string_alloc((size_t) msg_len, 0); + msg = zend_string_alloc(msg_len, 0); if (crypto_sign_open((unsigned char *) ZSTR_VAL(msg), &msg_real_len, msg_signed, (unsigned long long) msg_signed_len, publickey) != 0) { zend_string_efree(msg); RETURN_FALSE; } - if (msg_real_len >= SIZE_MAX || msg_real_len > msg_signed_len) { + if (msg_real_len >= ZSTR_MAX_LEN || msg_real_len > msg_signed_len) { zend_string_efree(msg); zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); RETURN_THROWS(); @@ -1222,7 +1222,7 @@ PHP_FUNCTION(sodium_crypto_stream) sodium_remove_param_values_from_backtrace(EG(exception)); RETURN_THROWS(); } - if (ciphertext_len <= 0 || ciphertext_len >= SIZE_MAX) { + if (ciphertext_len <= 0 || ciphertext_len >= ZSTR_MAX_LEN) { zend_argument_error(sodium_exception_ce, 1, "must be greater than 0"); RETURN_THROWS(); } @@ -1302,7 +1302,7 @@ PHP_FUNCTION(sodium_crypto_stream_xchacha20) sodium_remove_param_values_from_backtrace(EG(exception)); RETURN_THROWS(); } - if (ciphertext_len <= 0 || ciphertext_len >= SIZE_MAX) { + if (ciphertext_len <= 0 || ciphertext_len >= ZSTR_MAX_LEN) { zend_argument_error(sodium_exception_ce, 1, "must be greater than 0"); RETURN_THROWS(); } @@ -1619,7 +1619,7 @@ PHP_FUNCTION(sodium_crypto_pwhash_scryptsalsa208sha256) sodium_remove_param_values_from_backtrace(EG(exception)); RETURN_THROWS(); } - if (hash_len <= 0 || hash_len >= SIZE_MAX || hash_len > 0x1fffffffe0ULL) { + if (hash_len <= 0 || hash_len >= ZSTR_MAX_LEN || hash_len > 0x1fffffffe0ULL) { zend_argument_error(sodium_exception_ce, 1, "must be greater than 0"); RETURN_THROWS(); } @@ -1774,7 +1774,7 @@ PHP_FUNCTION(sodium_crypto_aead_aes256gcm_encrypt) zend_argument_error(sodium_exception_ce, 4, "must be SODIUM_CRYPTO_AEAD_AES256GCM_KEYBYTES bytes long"); RETURN_THROWS(); } - if (SIZE_MAX - msg_len <= crypto_aead_aes256gcm_ABYTES) { + if (ZSTR_MAX_LEN - msg_len <= crypto_aead_aes256gcm_ABYTES) { zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); RETURN_THROWS(); } @@ -1792,7 +1792,7 @@ PHP_FUNCTION(sodium_crypto_aead_aes256gcm_encrypt) zend_throw_exception(sodium_exception_ce, "internal error", 0); RETURN_THROWS(); } - if (ciphertext_real_len <= 0U || ciphertext_real_len >= SIZE_MAX || + if (ciphertext_real_len <= 0U || ciphertext_real_len >= ZSTR_MAX_LEN || ciphertext_real_len > ciphertext_len) { zend_string_efree(ciphertext); zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); @@ -1842,11 +1842,11 @@ PHP_FUNCTION(sodium_crypto_aead_aes256gcm_decrypt) RETURN_THROWS(); } msg_len = ciphertext_len; - if (msg_len >= SIZE_MAX) { + if (msg_len >= ZSTR_MAX_LEN) { zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); RETURN_THROWS(); } - msg = zend_string_alloc((size_t) msg_len, 0); + msg = zend_string_alloc(msg_len, 0); if (crypto_aead_aes256gcm_decrypt ((unsigned char *) ZSTR_VAL(msg), &msg_real_len, NULL, ciphertext, (unsigned long long) ciphertext_len, @@ -1854,7 +1854,7 @@ PHP_FUNCTION(sodium_crypto_aead_aes256gcm_decrypt) zend_string_efree(msg); RETURN_FALSE; } - if (msg_real_len >= SIZE_MAX || msg_real_len > msg_len) { + if (msg_real_len >= ZSTR_MAX_LEN || msg_real_len > msg_len) { zend_string_efree(msg); zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); RETURN_THROWS(); @@ -1897,12 +1897,12 @@ PHP_FUNCTION(sodium_crypto_aead_aegis128l_encrypt) zend_argument_error(sodium_exception_ce, 4, "must be SODIUM_CRYPTO_AEAD_AEGIS128L_KEYBYTES bytes long"); RETURN_THROWS(); } - if (SIZE_MAX - msg_len <= crypto_aead_aegis128l_ABYTES) { + if (ZSTR_MAX_LEN - msg_len <= crypto_aead_aegis128l_ABYTES) { zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); RETURN_THROWS(); } ciphertext_len = msg_len + crypto_aead_aegis128l_ABYTES; - ciphertext = zend_string_alloc((size_t) ciphertext_len, 0); + ciphertext = zend_string_alloc(ciphertext_len, 0); if (crypto_aead_aegis128l_encrypt ((unsigned char *) ZSTR_VAL(ciphertext), &ciphertext_real_len, msg, (unsigned long long) msg_len, @@ -1911,7 +1911,7 @@ PHP_FUNCTION(sodium_crypto_aead_aegis128l_encrypt) zend_throw_exception(sodium_exception_ce, "internal error", 0); RETURN_THROWS(); } - if (ciphertext_real_len <= 0U || ciphertext_real_len >= SIZE_MAX || + if (ciphertext_real_len <= 0U || ciphertext_real_len >= ZSTR_MAX_LEN || ciphertext_real_len > ciphertext_len) { zend_string_efree(ciphertext); zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); @@ -1957,11 +1957,11 @@ PHP_FUNCTION(sodium_crypto_aead_aegis128l_decrypt) RETURN_FALSE; } msg_len = ciphertext_len; - if (msg_len >= SIZE_MAX) { + if (msg_len >= ZSTR_MAX_LEN) { zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); RETURN_THROWS(); } - msg = zend_string_alloc((size_t) msg_len, 0); + msg = zend_string_alloc(msg_len, 0); if (crypto_aead_aegis128l_decrypt ((unsigned char *) ZSTR_VAL(msg), &msg_real_len, NULL, ciphertext, (unsigned long long) ciphertext_len, @@ -1969,7 +1969,7 @@ PHP_FUNCTION(sodium_crypto_aead_aegis128l_decrypt) zend_string_efree(msg); RETURN_FALSE; } - if (msg_real_len >= SIZE_MAX || msg_real_len > msg_len) { + if (msg_real_len >= ZSTR_MAX_LEN || msg_real_len > msg_len) { zend_string_efree(msg); zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); RETURN_THROWS(); @@ -2012,12 +2012,12 @@ PHP_FUNCTION(sodium_crypto_aead_aegis256_encrypt) zend_argument_error(sodium_exception_ce, 4, "must be SODIUM_CRYPTO_AEAD_AEGIS256_KEYBYTES bytes long"); RETURN_THROWS(); } - if (SIZE_MAX - msg_len <= crypto_aead_aegis256_ABYTES) { + if (ZSTR_MAX_LEN - msg_len <= crypto_aead_aegis256_ABYTES) { zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); RETURN_THROWS(); } ciphertext_len = msg_len + crypto_aead_aegis256_ABYTES; - ciphertext = zend_string_alloc((size_t) ciphertext_len, 0); + ciphertext = zend_string_alloc(ciphertext_len, 0); if (crypto_aead_aegis256_encrypt ((unsigned char *) ZSTR_VAL(ciphertext), &ciphertext_real_len, msg, (unsigned long long) msg_len, @@ -2026,7 +2026,7 @@ PHP_FUNCTION(sodium_crypto_aead_aegis256_encrypt) zend_throw_exception(sodium_exception_ce, "internal error", 0); RETURN_THROWS(); } - if (ciphertext_real_len <= 0U || ciphertext_real_len >= SIZE_MAX || + if (ciphertext_real_len <= 0U || ciphertext_real_len >= ZSTR_MAX_LEN || ciphertext_real_len > ciphertext_len) { zend_string_efree(ciphertext); zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); @@ -2072,11 +2072,11 @@ PHP_FUNCTION(sodium_crypto_aead_aegis256_decrypt) RETURN_FALSE; } msg_len = ciphertext_len; - if (msg_len >= SIZE_MAX) { + if (msg_len >= ZSTR_MAX_LEN) { zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); RETURN_THROWS(); } - msg = zend_string_alloc((size_t) msg_len, 0); + msg = zend_string_alloc(msg_len, 0); if (crypto_aead_aegis256_decrypt ((unsigned char *) ZSTR_VAL(msg), &msg_real_len, NULL, ciphertext, (unsigned long long) ciphertext_len, @@ -2084,7 +2084,7 @@ PHP_FUNCTION(sodium_crypto_aead_aegis256_decrypt) zend_string_efree(msg); RETURN_FALSE; } - if (msg_real_len >= SIZE_MAX || msg_real_len > msg_len) { + if (msg_real_len >= ZSTR_MAX_LEN || msg_real_len > msg_len) { zend_string_efree(msg); zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); RETURN_THROWS(); @@ -2126,12 +2126,12 @@ PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_encrypt) zend_argument_error(sodium_exception_ce, 4, "must be SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES bytes long"); RETURN_THROWS(); } - if (SIZE_MAX - msg_len <= crypto_aead_chacha20poly1305_ABYTES) { + if (ZSTR_MAX_LEN - msg_len <= crypto_aead_chacha20poly1305_ABYTES) { zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); RETURN_THROWS(); } ciphertext_len = msg_len + crypto_aead_chacha20poly1305_ABYTES; - ciphertext = zend_string_alloc((size_t) ciphertext_len, 0); + ciphertext = zend_string_alloc(ciphertext_len, 0); if (crypto_aead_chacha20poly1305_encrypt ((unsigned char *) ZSTR_VAL(ciphertext), &ciphertext_real_len, msg, (unsigned long long) msg_len, @@ -2140,7 +2140,7 @@ PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_encrypt) zend_throw_exception(sodium_exception_ce, "internal error", 0); RETURN_THROWS(); } - if (ciphertext_real_len <= 0U || ciphertext_real_len >= SIZE_MAX || + if (ciphertext_real_len <= 0U || ciphertext_real_len >= ZSTR_MAX_LEN || ciphertext_real_len > ciphertext_len) { zend_string_efree(ciphertext); zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); @@ -2186,7 +2186,7 @@ PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_decrypt) RETURN_FALSE; } msg_len = ciphertext_len; - if (msg_len >= SIZE_MAX) { + if (msg_len >= ZSTR_MAX_LEN) { zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); RETURN_THROWS(); } @@ -2198,7 +2198,7 @@ PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_decrypt) zend_string_efree(msg); RETURN_FALSE; } - if (msg_real_len >= SIZE_MAX || msg_real_len > msg_len) { + if (msg_real_len >= ZSTR_MAX_LEN || msg_real_len > msg_len) { zend_string_efree(msg); zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); RETURN_THROWS(); @@ -2239,7 +2239,7 @@ PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_ietf_encrypt) zend_argument_error(sodium_exception_ce, 4, "must be SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_IETF_KEYBYTES bytes long"); RETURN_THROWS(); } - if (SIZE_MAX - msg_len <= crypto_aead_chacha20poly1305_IETF_ABYTES) { + if (ZSTR_MAX_LEN - msg_len <= crypto_aead_chacha20poly1305_IETF_ABYTES) { zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); RETURN_THROWS(); } @@ -2257,7 +2257,7 @@ PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_ietf_encrypt) zend_throw_exception(sodium_exception_ce, "internal error", 0); RETURN_THROWS(); } - if (ciphertext_real_len <= 0U || ciphertext_real_len >= SIZE_MAX || + if (ciphertext_real_len <= 0U || ciphertext_real_len >= ZSTR_MAX_LEN || ciphertext_real_len > ciphertext_len) { zend_string_efree(ciphertext); zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); @@ -2300,7 +2300,7 @@ PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_ietf_decrypt) RETURN_THROWS(); } msg_len = ciphertext_len; - if (msg_len >= SIZE_MAX) { + if (msg_len >= ZSTR_MAX_LEN) { zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); RETURN_THROWS(); } @@ -2320,7 +2320,7 @@ PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_ietf_decrypt) zend_string_efree(msg); RETURN_FALSE; } - if (msg_real_len >= SIZE_MAX || msg_real_len > msg_len) { + if (msg_real_len >= ZSTR_MAX_LEN || msg_real_len > msg_len) { zend_string_efree(msg); zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); RETURN_THROWS(); @@ -2362,7 +2362,7 @@ PHP_FUNCTION(sodium_crypto_aead_xchacha20poly1305_ietf_encrypt) zend_argument_error(sodium_exception_ce, 4, "must be SODIUM_CRYPTO_AEAD_XCHACHA20POLY1305_IETF_KEYBYTES bytes long"); RETURN_THROWS(); } - if (SIZE_MAX - msg_len <= crypto_aead_xchacha20poly1305_IETF_ABYTES) { + if (ZSTR_MAX_LEN - msg_len <= crypto_aead_xchacha20poly1305_IETF_ABYTES) { zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); RETURN_THROWS(); } @@ -2376,7 +2376,7 @@ PHP_FUNCTION(sodium_crypto_aead_xchacha20poly1305_ietf_encrypt) zend_throw_exception(sodium_exception_ce, "internal error", 0); RETURN_THROWS(); } - if (ciphertext_real_len <= 0U || ciphertext_real_len >= SIZE_MAX || + if (ciphertext_real_len <= 0U || ciphertext_real_len >= ZSTR_MAX_LEN || ciphertext_real_len > ciphertext_len) { zend_string_efree(ciphertext); zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); @@ -2422,7 +2422,7 @@ PHP_FUNCTION(sodium_crypto_aead_xchacha20poly1305_ietf_decrypt) RETURN_FALSE; } msg_len = ciphertext_len; - if (msg_len - crypto_aead_xchacha20poly1305_IETF_ABYTES >= SIZE_MAX) { + if (msg_len - crypto_aead_xchacha20poly1305_IETF_ABYTES >= ZSTR_MAX_LEN) { zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); RETURN_THROWS(); } @@ -2439,7 +2439,7 @@ PHP_FUNCTION(sodium_crypto_aead_xchacha20poly1305_ietf_decrypt) zend_string_efree(msg); RETURN_FALSE; } - if (msg_real_len >= SIZE_MAX || msg_real_len > msg_len) { + if (msg_real_len >= ZSTR_MAX_LEN || msg_real_len > msg_len) { zend_string_efree(msg); zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); RETURN_THROWS(); @@ -2463,12 +2463,12 @@ PHP_FUNCTION(sodium_bin2hex) sodium_remove_param_values_from_backtrace(EG(exception)); RETURN_THROWS(); } - if (bin_len >= SIZE_MAX / 2U) { + if (bin_len >= ZSTR_MAX_LEN / 2U) { zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); RETURN_THROWS(); } hex_len = bin_len * 2U; - hex = zend_string_alloc((size_t) hex_len, 0); + hex = zend_string_alloc(hex_len, 0); sodium_bin2hex(ZSTR_VAL(hex), hex_len + 1U, bin, bin_len); ZSTR_VAL(hex)[hex_len] = 0; @@ -2501,7 +2501,7 @@ PHP_FUNCTION(sodium_hex2bin) zend_argument_error(sodium_exception_ce, 1, "must be a valid hexadecimal string"); RETURN_THROWS(); } - if (bin_real_len >= SIZE_MAX || bin_real_len > bin_len) { + if (bin_real_len >= ZSTR_MAX_LEN || bin_real_len > bin_len) { zend_string_efree(bin); zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); RETURN_THROWS(); @@ -2530,7 +2530,7 @@ PHP_FUNCTION(sodium_bin2base64) zend_argument_error(sodium_exception_ce, 2, "must be a valid base64 variant identifier"); RETURN_THROWS(); } - if (bin_len >= SIZE_MAX / 4U * 3U - 3U - 1U) { + if (bin_len >= ZSTR_MAX_LEN / 4U * 3U - 3U - 1U) { zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); RETURN_THROWS(); } @@ -2573,7 +2573,7 @@ PHP_FUNCTION(sodium_base642bin) zend_argument_error(sodium_exception_ce, 1, "must be a valid base64 string"); RETURN_THROWS(); } - if (bin_real_len >= SIZE_MAX || bin_real_len > bin_len) { + if (bin_real_len >= ZSTR_MAX_LEN || bin_real_len > bin_len) { zend_string_efree(bin); zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); RETURN_THROWS(); @@ -3201,7 +3201,7 @@ PHP_FUNCTION(sodium_crypto_kdf_derive_from_key) zend_argument_error(sodium_exception_ce, 1, "must be greater than or equal to SODIUM_CRYPTO_KDF_BYTES_MIN"); RETURN_THROWS(); } - if (subkey_len > crypto_kdf_BYTES_MAX || subkey_len > SIZE_MAX) { + if (subkey_len > crypto_kdf_BYTES_MAX || subkey_len > ZSTR_MAX_LEN) { zend_argument_error(sodium_exception_ce, 1, "must be less than or equal to SODIUM_CRYPTO_KDF_BYTES_MAX"); RETURN_THROWS(); } @@ -3457,7 +3457,7 @@ PHP_FUNCTION(sodium_crypto_secretstream_xchacha20poly1305_push) RETURN_THROWS(); } if (msg_len > crypto_secretstream_xchacha20poly1305_MESSAGEBYTES_MAX || - msg_len > SIZE_MAX - crypto_secretstream_xchacha20poly1305_ABYTES) { + msg_len > ZSTR_MAX_LEN - crypto_secretstream_xchacha20poly1305_ABYTES) { zend_argument_error(sodium_exception_ce, 2, "must be at most SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_MESSAGEBYTES_MAX bytes long"); RETURN_THROWS(); } @@ -3466,7 +3466,7 @@ PHP_FUNCTION(sodium_crypto_secretstream_xchacha20poly1305_push) RETURN_THROWS(); } c_len = msg_len + crypto_secretstream_xchacha20poly1305_ABYTES; - c = zend_string_alloc((size_t) c_len, 0); + c = zend_string_alloc(c_len, 0); if (crypto_secretstream_xchacha20poly1305_push ((void *) state, (unsigned char *) ZSTR_VAL(c), &c_real_len, msg, (unsigned long long) msg_len, ad, (unsigned long long) ad_len, @@ -3475,7 +3475,7 @@ PHP_FUNCTION(sodium_crypto_secretstream_xchacha20poly1305_push) zend_throw_exception(sodium_exception_ce, "internal error", 0); RETURN_THROWS(); } - if (c_real_len <= 0U || c_real_len >= SIZE_MAX || c_real_len > c_len) { + if (c_real_len <= 0U || c_real_len >= ZSTR_MAX_LEN || c_real_len > c_len) { zend_string_efree(c); zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); RETURN_THROWS(); @@ -3559,7 +3559,7 @@ PHP_FUNCTION(sodium_crypto_secretstream_xchacha20poly1305_pull) zend_string_efree(msg); RETURN_FALSE; } - if (msg_real_len >= SIZE_MAX || msg_real_len > msg_len) { + if (msg_real_len >= ZSTR_MAX_LEN || msg_real_len > msg_len) { zend_string_efree(msg); zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); RETURN_THROWS();