1343 Commits
Author SHA1 Message Date
Jakub Zelenka 31aacfb651 Merge branch 'PHP-8.6'
* PHP-8.6:
  Fix StreamPollHandle changing unread_bytes of a TLS stream when added
2026-10-04 19:45:20 +02:00
Jakub Zelenka 8330ca37ed Fix StreamPollHandle changing unread_bytes of a TLS stream when added
StreamPollHandle took the descriptor through the select cast. On a TLS
stream that cast reads: it moves what OpenSSL holds decrypted into the
stream buffer so that stream_select() can report it. Adding a watcher to
an Io\Poll\Context therefore read from the stream, filled the buffer of a
stream set unbuffered with stream_set_read_buffer() and changed
unread_bytes. That is not how the poll API should behave. Adding a handle
is a registration and must leave the stream as it found it, and the data
that moved was not reported by the watcher anyway, as bytes held by the
stream layer are not readiness of the descriptor.

A new cast PHP_STREAM_AS_FD_FOR_POLL returns the descriptor and nothing
else. The socket, TLS, plain and pgsql wrappers answer it, a userspace
wrapper sees it as STREAM_CAST_FOR_SELECT and the stream it returns is
cast the same way, and a filtered stream allows it like the select cast.
StreamPollHandle uses it, so adding a TLS stream leaves its buffer and
unread_bytes as they were. The select cast and stream_select() are
unchanged.

This is fixed in 8.6 because the API is new there and this is the
behaviour it should ship with. Keeping a read inside the registration
would complicate things later: once reads on a TLS stream can suspend,
the cast would become a nested read on a stream with an operation in
flight, and changing the cast then would change the visible behaviour of
a released API.
2026-10-04 19:43:45 +02:00
Gina Peter Banyard a0da45b535 pgsql: use new zend_object_copy() API 2026-10-01 12:43:57 +01:00
David Carlier 931d8ea4e1 Merge branch 'PHP-8.5' into PHP-8.6
* PHP-8.5:
  ext/pgsql: Removed `pg_service()`, unavailable with any released libpq

# Conflicts:
#	ext/pgsql/pgsql.c
#	ext/pgsql/pgsql_arginfo.h
2026-09-24 04:48:20 +01:00
武田 憲太郎 43c6014670 ext/pgsql: Removed pg_service(), unavailable with any released libpq
`PQservice()` never shipped in a released libpq; it was dropped during the
PostgreSQL 18 beta.

Close GH-23857
2026-09-24 04:47:49 +01:00
Ilia Alshanetsky 0744a9072a Merge branch 'PHP-8.5'
* PHP-8.5:
  ext/pgsql: Restore binary-safe pg_lo_write()
2026-09-13 10:21:38 -04:00
Ilia Alshanetsky c135a869c1 ext/pgsql: Restore binary-safe pg_lo_write()
The conversion of the data parameter to Z_PARAM_PATH_STR() made
pg_lo_write() reject any data containing a null byte, breaking writes of
arbitrary binary payloads which were accepted before. Accept embedded
null bytes again by parsing the data as a length-aware string. Sibling
audit: the other Z_PARAM_PATH* conversions from the same change
(pg_connect(), pg_lo_import(), table/statement identifiers) operate on
paths or SQL text where null-byte rejection is intentional.

Closes GH-23649
2026-09-13 10:17:47 -04:00
Dmytro Kulyk 67135cb97b gen_stub: Conditionally include zend_attributes.h to arginfo based on usage (#21570)
Headers required by the generated code (zend_attributes.h, zend_constants.h, zend_enum.h) are collected during generation and emitted as includes at the top of the arginfo file, with the same preprocessor conditions and PHP version guards as the code that needs them.

Removes the manual zend_attributes.h and zend_enum.h includes from sources that only needed them for the arginfo file they include.
2026-09-06 21:25:20 +02:00
lacatoire 65ae1ad847 ext/pgsql: stop advertising PGSQL_DML_ASYNC where it is refused
pg_update() and pg_delete() list PGSQL_DML_ASYNC among the valid flags in
the error they raise, although their masks reject it and their helpers
assert it is never set. Conversely pg_insert() and pg_update() accept the
whole PGSQL_CONV_OPTS set but only named PGSQL_CONV_FORCE_NULL, so
PGSQL_CONV_IGNORE_DEFAULT and PGSQL_CONV_IGNORE_NOT_NULL are added.

While there, widen php_pgsql_delete()'s assert to PGSQL_DML_NO_CONV,
which pg_delete() accepts and the helper itself consults.

Close GH-23480
2026-08-27 21:05:19 +01:00
Gina Peter Banyard ee908f5542 Zend: normalise behaviour around class name ZPP specifier (#23359)
Splitting the behavioural change of #23052 out into this and come up with something that is hopefully more sensible and consistent between fast and slow ZPP and the object or class_name Fast ZPP specifier.
2026-08-21 13:31:45 +01:00
lacatoire fb604aab1d ext/pgsql: fix the class name casing of pg_close_stmt()'s connection
The stub spelled it Pgsql\Connection, the only such spelling in the
extension. Resolution is case-insensitive, but Reflection reported a
class name that does not match the declared one.

Close GH-23393
2026-08-20 21:37:42 +01:00
Weilin Du 600e4a8445 tree-wide: Refactor with zend_string_ends_with* (#23216) 2026-08-14 17:01:16 +08:00
Gina Peter Banyard 0b14af3b98 standard: deprecate aliases with non canonical type name
Fix tests using non canonical versions and improve existing tests.

RFC:
- https://wiki.php.net/rfc/deprecations_php_8_6#deprecate_is_double
- https://wiki.php.net/rfc/deprecations_php_8_6#deprecate_is_integer
- https://wiki.php.net/rfc/deprecations_php_8_6#deprecate_is_long
- https://wiki.php.net/rfc/deprecations_php_8_6#deprecate_doubleval
2026-08-10 18:21:19 +01:00
NickSdot 5d58876192 tests: Cache failed service probes (#22944)
Prevents unavailable optional test services from slowing the suite through repeated connection timeouts. PDO and SNMP availability probes cache the first failure for the duration of one test run, so later SKIPIF checks return immediately.

Only failures are cached; successful probes and test connections are unchanged. PDOs one second timeout applies only to the default availability probe. The caches are private, run-scoped and removed afterwards. A service becoming available mid run is detected on the next test-suite run.
2026-08-06 11:42:56 +02:00
NickSdot 4905ce8e55 ext/pgsql: applied fixers to improve test robustness (#23040) 2026-08-04 18:13:33 +01:00
Ilija Tovilo fb21752483 Merge branch 'PHP-8.5'
* PHP-8.5:
  Fix out-of-bounds write in ext-bcmath bccomp() via bc_str2num()
  Add NEWS entries
  Fix GHSA-vc5h-9ppw-p5f3: phar circular symlink crash
  Fix SQL injection in ext-pgsql via E'...' backslash breakout
  libgd patch for CVE-2026-9672
2026-07-28 11:58:05 +02:00
Ilija Tovilo e5c3b4b083 Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Fix out-of-bounds write in ext-bcmath bccomp() via bc_str2num()
  Add NEWS entries
  Fix GHSA-vc5h-9ppw-p5f3: phar circular symlink crash
  Fix SQL injection in ext-pgsql via E'...' backslash breakout
  libgd patch for CVE-2026-9672
2026-07-28 11:51:44 +02:00
Ilija Tovilo d3f361c3b7 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Add NEWS entries
  Fix GHSA-vc5h-9ppw-p5f3: phar circular symlink crash
  Fix SQL injection in ext-pgsql via E'...' backslash breakout
  libgd patch for CVE-2026-9672
2026-07-28 11:50:34 +02:00
Ilija Tovilo 416985389d Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Add NEWS entries
  Fix GHSA-vc5h-9ppw-p5f3: phar circular symlink crash
  Fix SQL injection in ext-pgsql via E'...' backslash breakout
  libgd patch for CVE-2026-9672
2026-07-28 11:41:07 +02:00
Ilija Tovilo ab048bd83b Fix SQL injection in ext-pgsql via E'...' backslash breakout
php_pgsql_add_quotes() quotes the string with E'...', but PQescapeStringConn()
does not escape \ unless standard_conforming_strings is off.
PQescapeStringConn() is meant to be used with '', so do that instead.

Fixes GHSA-7qpv-r5mr-78m4
2026-07-28 11:11:57 +02:00
Calvin Buckley de5a5820ef Use php_pollfd_for_ms more consistently for single fd polling (#22872)
* ftp: For single fd poll calls, use php_pollfd_for_ms

* pgsql: Use php_pollfd_for_ms in compat shim

This is only used on pre-libpq 17.

* fastcgi: Use php_pollfd_for_ms for single fd

This also handles the case where poll isn't available (does that even
matter nowadays?)

* io: Use php_pollfd_for_ms for single fd poll

* cli: Convert to php_pollfd_for from select

This is not a poll call, but it is functionally the same as one; convert
it to the single fd polling function which is clearer to read.
2026-07-24 15:14:46 -03:00
Weilin Du 00f4cd6b80 Refactor various raw C-string concatenation to use existing API (#22879)
In #21607 we introduce several inline helpers for raw C-string concatenation.
This PR use them to refactor several manual C string construction.
2026-07-25 01:06:29 +08:00
Peter Kokot ecb2c73cb8 ext/pgsql: Remove unused HAVE_DECL_PGRES_TUPLES_CHUNK (#22456) 2026-06-26 17:55:20 +02:00
Tim Düsterhus 69e023fd84 ext/*: Make X_from_obj(zend_object *obj) functions macros (#22183)
* ext/*: Make `X_from_obj(zend_object *obj)` functions macros

With the introduction of the `ZEND_CONTAINER_OF()` macro we can now preserve
whether or not the `zend_object *` is `const` when extracting the
class-specific struct. This change will allow to use `const zend_object *` in
more locations.

Changes performed with Coccinelle followed by some manual cleanup for comment
and whitespace formatting:

    @a@
    attribute name zend_always_inline;
    type T;
    identifier obj;
    identifier f;
    typedef zend_object;
    @@

     T* f(zend_object *obj) { return ZEND_CONTAINER_OF(obj, T, std); }
    + #define f(obj) ZEND_CONTAINER_OF(obj, T, std)

    @@
    identifier a.f;
    @@

    - f(...) { ... }

    @b@
    attribute name zend_always_inline;
    type T;
    identifier obj;
    identifier f;
    typedef zend_object;
    @@

     T* f(zend_object *obj) { return ZEND_CONTAINER_OF(obj, T, zo); }
    + #define f(obj) ZEND_CONTAINER_OF(obj, T, zo)

    @@
    identifier b.f;
    @@

    - f(...) { ... }

* sockets: Fix build

* odbc: Fix build
2026-06-01 10:21:03 +02:00
Tim Düsterhus ad7cce6527 zend_portability: Add ZEND_CONTAINER_OF() (#21903)
* zend_portability: Add `ZEND_CONTAINER_OF()`

* tree-wide: Use `ZEND_CONTAINER_OF()`

Changes made with Coccinelle:

    @@
    type T_container;
    identifier member;
    expression e;
    @@

    - (T_container *)(((char *)(e)) - offsetof(T_container, member))
    + ZEND_CONTAINER_OF(e, T_container, member)

    @@
    type T_container;
    identifier member;
    expression e;
    typedef uintptr_t;
    @@

    - (T_container *)(((uintptr_t)(e)) - offsetof(T_container, member))
    + ZEND_CONTAINER_OF(e, T_container, member)

    @@
    type T_container;
    identifier member;
    expression e;
    @@

    - (const T_container *)(((char *)(e)) - offsetof(T_container, member))
    + ZEND_CONTAINER_OF(e, T_container, member)

    @@
    type T_container;
    identifier member;
    expression e;
    typedef uintptr_t;
    @@

    - (const T_container *)(((uintptr_t)(e)) - offsetof(T_container, member))
    + ZEND_CONTAINER_OF(e, T_container, member)

* bcmath: Fix `get_bcmath_number_from_obj()` const-correctness

A follow-up change to the new `ZEND_CONTAINER_OF()` macro will preserve the
`const`-ness of the input pointer. By wrapping this macro inside a macro rather
an an inline function we can preserve the `const`-ness across all layers.

* zend_portability: Keep `const`-ness in `ZEND_CONTAINER_OF()`

* zend_portability: Add C++ version to `ZEND_CONTAINER_OF()`
2026-05-19 10:47:00 +02:00
David Carlier 392a84d7e1 ext/pgsql: clean up pg_fetch_object() constructor handling.
Move object_init_ex() before php_pgsql_fetch_hash() so abstract,
interface and enum errors surface earlier, look up the constructor
via the get_constructor handler (under EG(fake_scope)) so classes
with overridden handlers work, and mark the object as ctor-failed
when the constructor throws.

The ValueError for ctor args on a class without a constructor now
reports argument 4 ($constructor_args) instead of argument 3 ($class).

close GH-21884
2026-04-29 12:29:11 +01:00
Tim Düsterhus 7114314c5a tree-wide: Replace XtOffsetOf by its definition (#21899)
`offsetof()` is in `stddef.h` and thus always available. The extra macro is an
unnecessary layer of indirection.
2026-04-28 22:12:56 +02:00
Ben Ramsey 7740a4e8e4 license-update: ext/pgsql source headers
RFC: https://wiki.php.net/rfc/php_license_update
2026-04-11 21:20:54 -05:00
Tim Düsterhus 04f06e8cf2 zend_portability: Remove EMPTY_SWITCH_DEFAULT_CASE() (#20063)
There are several issues with this macro:

- It is incorrectly named: It's not an empty default case. It's an unreachable
  default case.
- It is hiding control flow in its definition, which can be confusing for
  humans and tools (such as Coccinelle) alike, because it looks like it would
  be a statement that belongs to the "current" case rather than opening a new
  one.

Since this macro is exactly as long as explicitly spelling out its definition
(excluding the useless `break;`), it is not even making the code any more
succinct.
2026-04-06 14:46:15 +02:00
Peter Kokot 3619caa0b1 ext/{pdo_pgsql,pgsql}: Enable HAVE_PG_RESULT_MEMORY_SIZE (#21595)
PQresultMemorySize is available since libpq 12.
On Windows libpq 16.2 is used at time of writing:
https://github.com/winlibs/postgresql
2026-04-02 19:40:00 +02:00
Weilin Du 818bc8a177 ext/pgsql: Remove unnecessary +1 in memcpy when appending newline (GH-21597) 2026-04-02 15:47:39 +02:00
Weilin Du 2918caee20 ext/*: Remove break after return (#21485) 2026-03-23 20:30:13 +01:00
Arshid d3727f44e7 ext/pgsql: Remove unreachable break (#21482) 2026-03-21 09:39:44 +00:00
武田 憲太郎 31962aa086 ext/pgsql: Enable lo_tell64/lo_truncate64 by removing dead VE_PG_LO64 guards
The guards reference undefined VE_PG_LO64, a misspelling of
HAVE_PG_LO64 (removed in GH-14628), making the 64-bit code paths
permanently dead. Remove the guards to unconditionally enable the
64-bit variants for PostgreSQL >= 9.3, consistent with pg_lo_seek().

Dropped from GH-21386 as not suitable for backport.

close GH-21437
2026-03-14 05:22:43 +00:00
Gina Peter Banyard c658d3c787 ext/pgsql: use smart_str_append_double() instead of snprintf call (#21406) 2026-03-11 01:51:53 +00:00
David Carlier 148dc1dd66 Merge branch 'PHP-8.5'
* PHP-8.5:
  ext/pgsql: Fix preprocessor guard typo that silently disabled a feature
2026-03-09 07:45:20 +00:00
David Carlier b0470d1669 Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  ext/pgsql: Fix preprocessor guard typo that silently disabled a feature
2026-03-09 07:42:53 +00:00
武田 憲太郎 35d98cb6ce ext/pgsql: Fix preprocessor guard typo that silently disabled a feature
Fix `PQTRACE_SUPPRESS_TIMESTAMPS` guard misspelling in pgsql.stub.php.

The guard has been misspelled as `PQTRACE_SUPPPRESS_TIMESTAMPS`
(three P's) since 7ec8ae12c4, preventing the
`PGSQL_TRACE_SUPPRESS_TIMESTAMPS` constant from being registered.

close GH-21386
2026-03-09 07:41:04 +00:00
KentarouTakeda c56e8caaed ext/pgsql, ext/pdo_pgsql: Remove preprocessor guards for symbols predating libpq 10 (#21384)
While working on php/doc-en#5409 to clean up outdated PostgreSQL
version notes in the documentation, I noticed that the source code
also retains #ifdef guards for symbols guaranteed to exist in
libpq >= 10.0 (the minimum enforced in build/php.m4 via
PQencryptPasswordConn).

Removed guards (all confirmed in PostgreSQL 10 documentation):

- `PG_DIAG_{INTERNAL_POSITION,INTERNAL_QUERY}`: libpq 8.0+
- `PG_DIAG_{SCHEMA,TABLE,COLUMN,DATATYPE,CONSTRAINT}_NAME`: libpq 9.3+
- `PG_DIAG_SEVERITY_NONLOCALIZED`: libpq 9.6+
- `CONNECTION_SSL_STARTUP`: libpq 8.0+
- `CONNECTION_CONSUME`: libpq 10.0+

Refs:
- https://www.postgresql.org/docs/10/libpq-exec.html#LIBPQ-PQRESULTERRORFIELD
- https://www.postgresql.org/docs/10/libpq-connect.html#LIBPQ-PQCONNECTSTARTPARAMS
- https://github.com/php/php-src/blob/53e31d58834ef04375dae7bdc549d73dae371c5a/build/php.m4#L1927
2026-03-08 05:42:50 +00:00
Peter Kokot f17c5ad83b Windows build: Add new function CHECK_HEADER() (#21191)
The current function `CHECK_HEADER_ADD_INCLUDE()` automatically defines
`HAVE_<HEADER_NAME_H>` preprocessor macros, which makes it difficult to
sync with other build systems. Specially, if some `HAVE_` macro is used
in the code and this function defines this macro but Autotools doesn't.

The new `CHECK_HEADER()` function behaves similar except it doesn't
define the `HAVE_<HEADER_NAME_H>` preprocessor macro.

This removes the following unused compile definitions:

HAVE_ARGON2_H
HAVE_AVIF_H
HAVE_BZLIB_H
HAVE_CAPSTONE_CAPSTONE_H
HAVE_CURL_EASY_H
HAVE_DB_H
HAVE_DECODE_H
HAVE_DEPOT_H
HAVE_EDITLINE_READLINE_H
HAVE_ENCHANT_H
HAVE_ENCODE_H
HAVE_FFI_H
HAVE_FIREBIRD_INTERFACE_H
HAVE_FT2BUILD_H
HAVE_GD_H
HAVE_GLIB_H
HAVE_GMP_H
HAVE_HTTPD_H
HAVE_IBASE_H
HAVE_IR_IR_H
HAVE_KECCAKHASH_H
HAVE_LBER_H
HAVE_LDAP_H
HAVE_LIBEXSLT_EXSLT_H
HAVE_LIBINTL_H
HAVE_LIBPQ_FE_H
HAVE_LIBTIDY_TIDY_H
HAVE_LIBXML_PARSER_H
HAVE_LIBXML_TREE_H
HAVE_LIBXML_XMLWRITER_H
HAVE_LIBXSLT_XSLT_H
HAVE_LMDB_H
HAVE_MBSTRING_H
HAVE_MYSQL_H
HAVE_ONIGURUMA_H
HAVE_OPENSSL_SSL_H
HAVE_PNG_H
HAVE_SNMP_H
HAVE_SODIUM_H
HAVE_SQLITE3_H
HAVE_SQLITE3EXT_H
HAVE_SYBFRONT_H
HAVE_TIDY_H
HAVE_TIDY_TIDY_H
HAVE_TIDYBUFFIO_H
HAVE_TIMELIB_CONFIG_H
HAVE_UNICODE_USPOOF_H
HAVE_UNICODE_UTF_H
HAVE_XPM_H
HAVE_ZIP_H
HAVE_ZIPCONF_H
HAVE_ZLIB_H

The following compile definitions are defined explicitly:

- HAVE_ICONV_H
- HAVE_MSCOREE_H
- HAVE_SQL_H
- HAVE_SQLEXT_H

Additionally, the `SETUP_OPENSSL()` function doesn't accept the 6th
argument anymore.
2026-03-03 20:06:40 +01:00
David Carlier 297b25316b Merge branch 'PHP-8.5'
* PHP-8.5:
  ext/pgsql: fix GH-21165 unit test.
2026-02-17 04:27:35 +00:00
David Carlier 8ca6e13c2d Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  ext/pgsql: fix GH-21165 unit test.
2026-02-17 04:27:21 +00:00
David Carlier f7af877cfe ext/pgsql: fix GH-21165 unit test.
making it fails early instead.

close GH-21234
2026-02-17 04:26:42 +00:00
David Carlier 49f903ccc2 Merge branch 'PHP-8.5'
* PHP-8.5:
  Fix GH-21162: pg_connect() on error memory leak.
2026-02-15 21:27:29 +00:00
David Carlier 6c8a71b3b7 Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Fix GH-21162: pg_connect() on error memory leak.
2026-02-15 21:27:19 +00:00
David Carlier 539c5d9f76 Fix GH-21162: pg_connect() on error memory leak.
The PHP_PQ_ERROR macro calls php_error_docref() which triggers user error handlers
thus libpq does not have the chance to clean the resources (and empty
connections string are allowed) on failure thus we avoid this macro
and delay the error handling after.

close GH-21165
2026-02-15 21:26:23 +00:00
Arshid daa3513c32 ext/pgsql: pg_lo_export/pg_connection_reset returning a boolean value using RETURN_BOOL (#21150) 2026-02-06 06:59:33 +00:00
Khaled Alam 32bd33983d Remove unreachable code after zend_error_noreturn calls (GH-20983) 2026-02-02 14:14:15 +01:00
Arnaud Le Blanc 65b4073922 Include the actual stub name in generated arginfo headers (#20993) 2026-01-21 20:57:00 +01:00
David Carlier e9e0fe45e5 Merge branch 'PHP-8.5'
* PHP-8.5:
  exp/pgsql: insert/update query string build possible UB fix.
2026-01-19 06:18:26 +00:00