Skip to content
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
12 changes: 12 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions Zend/zend_bitset.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
41 changes: 21 additions & 20 deletions ext/pgsql/pgsql.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) { \
Expand All @@ -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);
Expand All @@ -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);

Expand Down Expand Up @@ -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();
}

Expand Down
6 changes: 6 additions & 0 deletions ext/pgsql/tests/05large_object.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions ext/pgsql/tests/pg_close_stmt.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -29,5 +34,6 @@ pg_close($db);

?>
--EXPECT--
pg_close_stmt(): Argument #2 ($statement_name) must not be empty
bool(true)
bool(true)
Loading
Loading