Commit graph

600 commits

Author SHA1 Message Date
Niels Dossche
d15e119d07
Use cheaper functions to get member name in PDO (#18769) 2025-06-05 17:46:56 +02:00
Niels Dossche
3ba725a556
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-18309: ipv6 filter integer overflow
  Fix GH-18304: Changing the properties of a DateInterval through dynamic properties triggers a SegFault
2025-04-11 23:36:42 +02:00
Niels Dossche
a019fbd970
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-18309: ipv6 filter integer overflow
  Fix GH-18304: Changing the properties of a DateInterval through dynamic properties triggers a SegFault
2025-04-11 23:36:12 +02:00
Niels Dossche
ba0853888d
Fix GH-18304: Changing the properties of a DateInterval through dynamic properties triggers a SegFault
For dynamic fetches the cache_slot will be NULL, so we have to check for
that when resetting the cache. For zip and xmlreader this couldn't
easily be tested because of a lack of writable properties.

Closes GH-18307.
2025-04-11 23:33:58 +02:00
Niels Dossche
c4a79617a9
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix memory leak when destroying PDORow
2025-03-20 23:14:37 +01:00
Niels Dossche
0ef57501d9
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix memory leak when destroying PDORow
2025-03-20 23:14:14 +01:00
Niels Dossche
2dde07af55
Fix memory leak when destroying PDORow
This should call zend_object_std_dtor() to clean the property table etc.
This also has a semantic influence because previously weak refs were not
notified for example.

This fixes the final issue in GH-18114 (the crash was master-only and
fixed already).

Closes GH-18114.
Closes GH-18123.
2025-03-20 23:13:42 +01:00
Niels Dossche
e1eeb483ef
Fix GH-18114: pdo lazy object crash (#18116)
Since 0537968, the properties are no longer initialized.
So we call object_properties_init to handle that correctly.
Lower branches have a memory leak, but that requires a separate fix.
2025-03-19 23:43:30 +01:00
Niels Dossche
d95b9d6d32
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-17736: Assertion failure zend_reference_destroy()
2025-03-02 22:41:21 +01:00
Niels Dossche
ee4a9a4a7c
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-17736: Assertion failure zend_reference_destroy()
2025-03-02 22:37:07 +01:00
Niels Dossche
ce8ab5f16a
Fix GH-17736: Assertion failure zend_reference_destroy()
The cache slot for FETCH_OBJ_W in function `test` is primed with the
class for C. The next call uses a simplexml instance and reuses the same
cache slot. simplexml's get_property_ptr handler does not use the cache
slot, so the old values remain in the cache slot. When
`zend_handle_fetch_obj_flags` is called this is not guarded by a check
for the class entry. So we end up using the prop_info from the property
C::$a instead of the simplexml property.

This patch adds a reset to the cache slots in the property address fetch
code and also in the extensions with a non-standard reference handler.
This keeps the run time cache consistent and avoids the issue without
complicating the fast paths.

Closes GH-17739.
2025-03-02 22:33:32 +01:00
Gina Peter Banyard
4e55889dca
ext/pdo: Refactor validation of fetch mode in PDO statement (#17699)
Co-authored-by: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
2025-02-09 00:35:33 +00:00
Gina Peter Banyard
4fcbdea974 ext/pdo: Turn lazy_object_ref into a zend_object* from a zval
This saves 8 bytes
2025-02-04 11:23:08 +00:00
Gina Peter Banyard
481bafe943 ext/pdo: Add static modifier for PDORow object handlers 2025-02-04 11:23:08 +00:00
Niels Dossche
e306a2e0e8
Add missing NULL checks in dbstmt_get_gc
This fixes the nightly Laravel failure: 3651202379
2025-02-01 23:58:44 +01:00
Niels Dossche
8deca2838c
Fix initializer for older C compilers 2025-01-31 22:45:03 +01:00
Kalle Sommer Nielsen
ed320b500c Fix C23 syntax for VS16 (CI runs VS22) 2025-01-31 22:28:31 +02:00
Gina Peter Banyard
3ff7758bcf ext/pdo: Refactor PDO::FETCH_CLASS to not rely on a FCI and use a HashTable for ctor_arg
To call the constructor we now only store the CE and a HashTable for the arguments.
This reduces the size of the _pdo_stmt_t struct from 320 bytes to 232 bytes.
Moreover, this now means that the constructor argument array follows the usual CUFA semantics.
This change is a BC break, as string keys now act like named arguments.
Moreover, the automatic wrapping of by-value arguments for by-ref parameters has been dropped, and the usual E_WARNING is now emitted in those cases.

The do_fetch() is heavily refactored to simplify the execution flow, which also makes it easier to understand.
Additionally we add a new bitflag in_fetch to prevent modification of the fetch flags by userland when PDO is fetching from the DB.
2025-01-30 18:48:54 +00:00
Gina Peter Banyard
09791ed1d1
ext/pdo: Convert database_object_handle zval to zend_object* (#17629)
This saves 8 bytes on the PDO statement struct.

We change the PGSQL PDO driver API to take a zend_object* instead of a zval* at the same time.
2025-01-30 18:34:03 +00:00
Gina Peter Banyard
0537968f00
ext/pdo: Use zend_object_alloc() for allocating PDORows (#17621)
Follow-up for GH-17606
2025-01-29 19:33:19 +00:00
Gina Peter Banyard
b667939b57
ext/pdo: Fix zend_object std layout for _pdo_row_t (#17606)
As of PHP 7 [1] the `std` should be at the end of the struct instead of at the beginning.

See GH-17598 for more UB related details.

[1] https://www.npopov.com/2015/06/19/Internal-value-representation-in-PHP-7-part-2.html#objects-in-php-7
2025-01-29 12:50:01 +00:00
Gina Peter Banyard
60ee42eb3e
Merge branch 'PHP-8.4'
* PHP-8.4:
  ext/pdo: Fix a UAF when changing default fetch class ctor args
2025-01-26 23:41:42 +00:00
Gina Peter Banyard
7f321a1313
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  ext/pdo: Fix a UAF when changing default fetch class ctor args
2025-01-26 23:37:14 +00:00
Gina Peter Banyard
3027600ffc
ext/pdo: Fix a UAF when changing default fetch class ctor args
Co-authored-by: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
2025-01-26 23:32:35 +00:00
Gina Peter Banyard
6fc49ab518
ext/pdo: Convert FETCH_INTO zval to a zend_object pointer (#17525) 2025-01-24 22:59:56 +00:00
Gina Peter Banyard
5b06a066f6
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Add NEWS entries
  Fix crash in firebird statement dtor
  ext/pdo: Fix memory leak if GC needs to free PDO Statement
2025-01-24 20:22:13 +00:00
Gina Peter Banyard
8ed0d7fe96
Merge branch 'PHP-8.4'
* PHP-8.4:
  Add NEWS entries
  Fix crash in firebird statement dtor
  ext/pdo: Fix memory leak if GC needs to free PDO Statement
2025-01-24 20:20:11 +00:00
Gina Peter Banyard
eda8ce728a
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Add NEWS entries
  Fix crash in firebird statement dtor
  ext/pdo: Fix memory leak if GC needs to free PDO Statement
  Fix GHA config yml error
2025-01-24 20:20:01 +00:00
Gina Peter Banyard
99f8ec33d9
ext/pdo: Fix memory leak if GC needs to free PDO Statement 2025-01-24 20:16:12 +00:00
Gina Peter Banyard
b2480c3b55
Revert "Add into zval to GC buffer first"
I thought I was on a branch and not master oopsie

This reverts commit bd02141659.
2025-01-24 14:26:42 +00:00
Gina Peter Banyard
bd02141659
Add into zval to GC buffer first 2025-01-24 14:26:11 +00:00
Niels Dossche
c218f62920
Remove always-true check in pdo_stmt.c (#17535)
`check_empty` is checked earlier up, so this variable is always true.
2025-01-21 19:20:57 +01:00
Gina Peter Banyard
6bd2b8dfa5
ext/pdo: Throw an exception instead of fatal error if the class is not found (#17528) 2025-01-19 23:35:24 +00:00
Gina Peter Banyard
dfcac15739 ext/pdo: Rename variable, because i is really not descriptive 2025-01-15 03:02:30 +00:00
Gina Peter Banyard
8d79ed6b3e
ext/pdo: Refactor PDO::FETCH_FUNC to not rely on an FCI on the struct (#17420) 2025-01-09 22:22:52 +00:00
Gina Peter Banyard
fba0b18d35 ext/pdo: Remove mostly useless retval field in statement struct 2025-01-09 10:30:10 +00:00
Gina Peter Banyard
bd83f866d1 ext/pdo: Refactor FETCH_FUNCTION mode
Most of the fields on the struct are useless or can be handled differently
2025-01-09 10:30:10 +00:00
Gina Peter Banyard
e5c415cd3a
ext/pdo: Move assignment to declaration for clarity 2025-01-07 22:05:45 +00:00
Gina Peter Banyard
8c27553538
ext/pdo: Use a variable for the column name 2025-01-07 22:05:45 +00:00
Gina Peter Banyard
17ea79bb4e [skip ci] Remove useless comment 2025-01-07 09:10:05 +00:00
Gina Peter Banyard
19dd79bdee ext/pdo: Refactor PDOStatement::fetchAll()
This also refactors the internal do_fetch() function to stop doing wonky stuff to handle grouping, which is a feature of fetchAll

Handle PDO_FETCH_KEY_PAIR on its own as GROUP and UNIQUE flags can interfere with it
2025-01-07 09:10:05 +00:00
Gina Peter Banyard
1969955e50
ext/pdo: Drop redundant mode check, and fix the first check (#17302) 2025-01-01 20:22:39 +00:00
Saki Takamachi
74218530b6
Merge branch 'PHP-8.4'
* PHP-8.4:
  Added gc_handler to properly handle circular references. (#16703)
2024-11-06 20:32:53 +09:00
Saki Takamachi
a800a03562
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Added gc_handler to properly handle circular references. (#16703)
2024-11-06 20:32:33 +09:00
Saki Takamachi
ca27e40a5f
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Added gc_handler to properly handle circular references. (#16703)
2024-11-06 20:31:30 +09:00
Saki Takamachi
4d14325b19
Added gc_handler to properly handle circular references. (#16703)
closes #16703

Co-authored-by: Christoph M. Becker <cmbecker69@gmx.de>
2024-11-06 20:30:08 +09:00
Tim Düsterhus
3c8c0df6c8
pdo: Use zend_string_toupper in pdo_stmt_describe_columns (#16047)
zend_string_toupper was only introduced in PHP 8.2 and thus it likely was not
used here, since this code was last touched for PHP 8.0.
2024-09-25 14:52:02 +02:00
Gina Peter Bnayard
5853cdb73d Use "must not" instead of "cannot" wording 2024-08-21 21:12:17 +01:00
Gina Peter Bnayard
e7c4d54d65 Use new helper function for "cannot be empty" ValueErrors 2024-08-21 21:12:17 +01:00
Arnaud Le Blanc
1fbb666545
Use zend_std_build_properties() to access zend_object.properties
The zend_object.properties HashTable needs to be built just in time by calling
rebuild_object_properties() on the object before accessing it. Normally this is
done automatically in zend_std_get_properties(), but we do it manually in a few
places.

In this change I introduce an inline variant of zend_std_build_properties(), and
refactor these places to use it instead of calling rebuild_object_properties()
manually.

rebuild_object_properties() renamed as rebuild_object_properties_internal(), to
enforce usage of zend_std_get_properties() or zend_std_build_properties_ex().

Closes GH-14996
2024-07-18 22:18:38 +02:00