1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 08:12:21 +01:00
Commit Graph

6534 Commits

Author SHA1 Message Date
Gina Peter Banyard
c33805791d sapi/fuzzer: Fetch function and call it directly instead of using a zval to hold the name (#19030) 2025-07-06 01:29:48 +01:00
Remi Collet
75006cf21d avoid false failure for long path (#18992) 2025-07-04 08:33:07 +02:00
Daniil Gentili
591b3249da Do not use RTLD_DEEPBIND if dlmopen is available (#18612)
DL_LOAD now doesn't use RTLD_DEEPBIND deepbind anymore on platforms
where dlmopen with LM_ID_NEWLM is available:
this means shared library symbol isolation (if needed) must be enabled on
the user side when requiring libphp.so, by using dlmopen with LM_ID_NEWLM
instead of dlopen.
RTLD_DEEPBIND is still enabled when the Apache SAPI is in use.

Closes GH-10670.
2025-06-23 21:44:58 +02:00
Niels Dossche
7f3a2bc727 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix 'phpdbg --help' segfault on shutdown with USE_ZEND_ALLOC=0
2025-06-10 19:23:03 +02:00
Niels Dossche
6685414a77 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix 'phpdbg --help' segfault on shutdown with USE_ZEND_ALLOC=0
2025-06-10 19:22:56 +02:00
Niels Dossche
0cd3ebfc40 Fix 'phpdbg --help' segfault on shutdown with USE_ZEND_ALLOC=0
This hack not only breaks the handling of custom allocators, but also
breaks if zend_alloc is compiled with USE_CUSTOM_MM.
This hack is just no good, if you want leak information then use ASAN.

Closes GH-18813.
2025-06-10 19:22:24 +02:00
Tim Düsterhus
5740607806 Merge branch 'PHP-8.4'
* PHP-8.4:
  cli: Fix tests/bug80092.phpt expectation for `PHP_BUILD_PROVIDER` (#18824)
2025-06-10 19:16:28 +02:00
Niels Dossche
eb151e39b0 Properly handle reference return value from __toString()
It's possible to return a reference from __toString(), but this is not
handled and results in a (confusing) error telling that the return value
must be a string.
Properly handle this by unwrapping the reference.

Closes GH-18810.
2025-06-10 19:15:53 +02:00
Tim Düsterhus
594221fff2 cli: Fix tests/bug80092.phpt expectation for PHP_BUILD_PROVIDER (#18824)
see afc5738154
see 40d88cacc1
2025-06-10 19:15:35 +02:00
Jakub Zelenka
b64daf9b3f Merge branch 'PHP-8.4' 2025-05-30 22:58:34 +02:00
Jakub Zelenka
39efe8ac1e Merge branch 'PHP-8.3' into PHP-8.4 2025-05-30 22:57:34 +02:00
txuna
48b492269b Fix GH-18595: fpm_get_status segfault
This fixes null dereference error when calling fpm_get_status() and one
of the children is just being created.

Closes GH-18662

Co-authored-by: Jakub Zelenka <bukka@php.net>
2025-05-30 22:55:53 +02:00
Niels Dossche
33ae76405f Use zend_string for arg_separators
This allows us to avoid a call to `zend_ini_str` which took 6% of the
profile on my i7-4790 for a call to `http_build_query`. Now we can just
grab the value from the globals.
In other files this can avoid some length recomputations.
2025-05-21 19:54:09 +02:00
Calvin Buckley
76791e90b9 Use win32 glob implementation on all platforms (#18164)
* Move glob to main/ from win32/

In preparation to make the Win32 reimplementation the standard
cross-platform one. Currently, it doesn't do that and just passes
through the original glob implementation. We could consider also having
an option to use the standard glob for systems that have a sufficient
one.

* Enable building with win32 glob on non-windows

Kind of broken. We're namespacing the function and struct, but not yet
the GLOB_* defines. There are a lot of places callers check if i.e.
NOMATCH is defined that would likely become redundant.

Currently it also has php_glob and #defines glob php_glob (etc.) - I
suspect doing the opposite and changing the callers would make more
sense, just doing MVP to geet it to build (even if it fails tests).

* Massive first pass at conversion to internal glob

Have not tested yet. the big things are:

- Should be invisible to userland PHP code.
- A lot of :%s/GLOB_/PHP_GLOB_/g; the diff can be noisy as a result,
  especially in comments.
- Prefixes everything with PHP_ to avoid conflicts with system glob in
  case it gets included transitively.
- A lot of weird shared definitions that were sprawled out to other
  headers are now included in php_glob.h.
- A lot of (but not yet all cases) of HAVE_GLOB are removed, since we
  can always fall back to php_glob.
- Using the system glob is not wired up yet; it'll need more shim
  ifdefs for each flag type than just glob_t/glob/globfree defs.

* Fix inclusion of GLOB_ONLYDIR

This is a GNU extension, but we don't need to implement it, as the GNU
implementation is flawed enough that callers have to manually filter it
anyways; just provide a stub definition for the constant.

We could consideer implementing this properly later. For now, fixes the
basic glob constant tests.

* Remove HAVE_GLOBs

We now always have a glob implementation that works. HAVE_GLOB should
only be used to check if we have a system implementation, for if we
decide to wrap the system implementation instead.

* We don't need to care about being POSIXly correct for internal glob

* Check for reallocarray

Ideally temporary until GH-17433.

* Forgot to move this file from win32/ to main/

* Check for issetugid (BSD function)

* Allow using the system glob with --enable-system-glob

* Style fix after removing ifdef

* Remove empty case for system glob
2025-05-20 16:20:59 -03:00
George Wang
3367f17f60 Merge branch 'PHP-8.4' 2025-05-15 11:53:27 -04:00
George Wang
72efe6dcdf Merge branch 'PHP-8.3' into PHP-8.4 2025-05-15 11:53:07 -04:00
George Wang
8e5b3129de Address compiler warnings. 2025-05-15 11:52:49 -04:00
Richard Schneeman
89dc8d79a7 cli: Fix swapped output in php --ini (#18557)
In #18527, I accidentally swapped the values. This is before my modification:

```
zend_printf("Configuration File (php.ini) Path: %s\n", PHP_CONFIG_FILE_PATH);
zend_printf("Loaded Configuration File:         %s\n", php_ini_opened_path ? php_ini_opened_path : "(none)");
zend_printf("Scan for additional .ini files in: %s\n", php_ini_scanned_path  ? php_ini_scanned_path : "(none)");
```

- "Loaded Configuration File" should be `php_ini_opened_path`
- "Scan for additional .ini files in" shoudl be `php_ini_scanned_path`
2025-05-14 21:36:20 +02:00
Richard Schneeman
331ac35f58 Fix visibility of whitespace in config output (#18527)
When a config var has whitespace (especially trailing whitespace) it is hard to see. This commit wraps the values (if they exist) in double quotes, so the difference is visually observable:

Before:

```
$ export PHP_INI_SCAN_DIR="/opt/homebrew/etc/php/8.4/conf.d         "
$ ./sapi/cli/php --ini
Configuration File (php.ini) Path: /usr/local/lib
Loaded Configuration File:         /opt/homebrew/etc/php/8.4/conf.d         
Scan for additional .ini files in: (none)
Additional .ini files parsed:      (none)
```

> Note 
> The above output has trailing whitespace that is not visible, you can see it if you copy it into an editor:

After:

```
$ ./sapi/cli/php --ini
Configuration File (php.ini) Path: "/usr/local/lib"
Loaded Configuration File:         "/opt/homebrew/etc/php/8.4/conf.d         "
Scan for additional .ini files in: (none)
Additional .ini files parsed:      (none)
```

Above the whitespace is now visible `/opt/homebrew/etc/php/8.4/conf.d         `.

Close #18390
2025-05-11 14:53:56 +01:00
Niels Dossche
3c84b01e02 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix leak+crash with sapi_windows_set_ctrl_handler()
2025-05-05 19:14:19 +02:00
Niels Dossche
d4a3e437ae Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix leak+crash with sapi_windows_set_ctrl_handler()
2025-05-05 19:14:13 +02:00
Niels Dossche
fb3536fd60 Fix leak+crash with sapi_windows_set_ctrl_handler()
The ctrl_handler is never destroyed. We have to destroy it at request
end so we avoid leaking it and also avoid keeping a reference to
previous request memory in a next request. The latter can result in a
crash and can be demonstrated with this script and `--repeat 2`:

```php
class Test {
	public function set() {
		sapi_windows_set_ctrl_handler(self::cb(...));
	}
	public function cb() {
	}
}

$test = new Test;
$test->set();
sleep(3);
```
When you hit CTRL+C in the second request you can crash.

This patch resolves both the leak and crash by destroying the
ctrl_handler after a request.

Closes GH-18231.
2025-05-05 19:13:39 +02:00
Niels Dossche
4152ca5c8a Fix fuzzer support after CALL VM changes (#18491) 2025-05-04 13:25:42 +02:00
DanielEScherzer
3f03f7ed3d [RFC] Add support for attributes on compile-time constants
https://wiki.php.net/rfc/attributes-on-constants
2025-04-29 11:53:09 -07:00
George Wang
2336aa684d Merge branch 'PHP-8.4' 2025-04-27 12:00:31 -04:00
George Wang
c08c5ded1a Merge branch 'PHP-8.3' into PHP-8.4 2025-04-27 12:00:12 -04:00
George Wang
03844d1f51 Update LSAPI version to V8.2 2025-04-27 11:59:40 -04:00
George Wang
78370689b8 Merge branch 'PHP-8.4' 2025-04-27 11:53:33 -04:00
George Wang
39a8e5e041 Merge branch 'PHP-8.3' into PHP-8.4 2025-04-27 11:53:14 -04:00
George Wang
58e5d0c240 Update max size of request headers from 65535 to 256K 2025-04-27 11:52:51 -04:00
George Wang
7cc7ae9d24 Merge branch 'PHP-8.4' 2025-04-27 11:47:52 -04:00
George Wang
e961488d98 Update SAPI_LITESPEED_PATH to sapi/litespeed/lsphp 2025-04-27 11:47:35 -04:00
George Wang
e4f2e4a99a Update SAPI_LITESPEED_PATH to sapi/litespeed/lsphp 2025-04-27 11:20:32 -04:00
David CARLIER
ba83d5daeb sapi/litespeed and ext/standard: Fix few build warnings. (#18265) 2025-04-19 10:18:53 +01:00
Arnaud Le Blanc
76d7c616bb Pass opline as argument to opcode handlers in CALL VM
This changes the signature of opcode handlers in the CALL VM so that the opline
is passed directly via arguments. This reduces the number of memory operations
on EX(opline), and makes the CALL VM considerably faster.

Additionally, this unifies the CALL and HYBRID VMs a bit, as EX(opline) is now
handled in the same way in both VMs.

This is a part of GH-17849.

Currently we have two VMs:

 * HYBRID: Used when compiling with GCC. execute_data and opline are global
   register variables
 * CALL: Used when compiling with something else. execute_data is passed as
   opcode handler arg, but opline is passed via execute_data->opline
   (EX(opline)).

The Call VM looks like this:

    while (1) {
        ret = execute_data->opline->handler(execute_data);
        if (UNEXPECTED(ret != 0)) {
            if (ret > 0) { // returned by ZEND_VM_ENTER() / ZEND_VM_LEAVE()
                execute_data = EG(current_execute_data);
            } else {       // returned by ZEND_VM_RETURN()
                return;
            }
        }
    }

    // example op handler
    int ZEND_INIT_FCALL_SPEC_CONST_HANDLER(zend_execute_data *execute_data) {
        // load opline
        const zend_op *opline = execute_data->opline;

        // instruction execution

        // dispatch
        // ZEND_VM_NEXT_OPCODE():
        execute_data->opline++;
        return 0; // ZEND_VM_CONTINUE()
    }

Opcode handlers return a positive value to signal that the loop must load a
new execute_data from EG(current_execute_data), typically when entering
or leaving a function.

Here I make the following changes:

 * Pass opline as opcode handler argument
 * Return next opline from opcode handlers
 * ZEND_VM_ENTER / ZEND_VM_LEAVE return opline|(1<<0) to signal that
   execute_data must be reloaded from EG(current_execute_data)

This gives us:

    while (1) {
        opline = opline->handler(execute_data, opline);
        if (UNEXPECTED((uintptr_t) opline & ZEND_VM_ENTER_BIT) {
            opline = opline & ~ZEND_VM_ENTER_BIT;
            if (opline != 0) { // ZEND_VM_ENTER() / ZEND_VM_LEAVE()
                execute_data = EG(current_execute_data);
            } else {           // ZEND_VM_RETURN()
                return;
            }
        }
    }

    // example op handler
    const zend_op * ZEND_INIT_FCALL_SPEC_CONST_HANDLER(zend_execute_data *execute_data, const zend_op *opline) {
        // opline already loaded

        // instruction execution

        // dispatch
        // ZEND_VM_NEXT_OPCODE():
        return ++opline;
    }

bench.php is 23% faster on Linux / x86_64, 18% faster on MacOS / M1.

Symfony Demo is 2.8% faster.

When using the HYBRID VM, JIT'ed code stores execute_data/opline in two fixed
callee-saved registers and rarely touches EX(opline), just like the VM.

Since the registers are callee-saved, the JIT'ed code doesn't have to
save them before calling other functions, and can assume they always
contain execute_data/opline. The code also avoids saving/restoring them in
prologue/epilogue, as execute_ex takes care of that (JIT'ed code is called
exclusively from there).

The CALL VM can now use a fixed register for execute_data/opline as well, but
we can't rely on execute_ex to save the registers for us as it may use these
registers itself. So we have to save/restore the two registers in JIT'ed code
prologue/epilogue.

Closes GH-17952
2025-04-15 18:51:54 +02:00
Jakub Zelenka
5ff8d6d0d2 Fix GH-17645: FPM with httpd ProxyPass does not decode script path
This changes make FPM always decode SCRIPT_FILENAME when Apache
ProxyPass or ProxyPassMatch is used. It also introduces a new INI
option fastcgi.script_path_encoded that allows using the previous
behavior of not decoding the path. The INI is introduced because
there is a chance that some users could use encoded file paths in
their file system as a workaround for the previous behavior.

Close GH-17896
2025-03-25 19:19:55 +01:00
Arnaud Le Blanc
53eaead824 Merge branch 'PHP-8.4'
* PHP-8.4:
  Disable ZEND_RC_MOD_CHECK() while loading shared extension in FPM
2025-03-17 17:40:38 +01:00
Arnaud Le Blanc
995f11adb1 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Disable ZEND_RC_MOD_CHECK() while loading shared extension in FPM
2025-03-17 17:40:23 +01:00
Arnaud Le Blanc
c531f3d79b Disable ZEND_RC_MOD_CHECK() while loading shared extension in FPM
This fixes a ZEND_RC_MOD_CHECK() assertion failure when building with
"-DZEND_RC_DEBUG=1 --enable-debug --enable-zts". php_dl() is called after
startup, and manipulates the refcount of persistent strings, which is not
allowed at this point of the lifecycle.

The dl() function disables the ZEND_RC_MOD_CHECK() assertion before calling
php_dl(). This change applies the same workaround in FPM.

Closes GH-18075
2025-03-17 17:40:05 +01:00
Niels Dossche
6d6ac81d41 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-18082: Memory leaks in fuzzer SAPI error paths
2025-03-16 16:39:01 +01:00
Niels Dossche
a67f351b67 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-18082: Memory leaks in fuzzer SAPI error paths
2025-03-16 16:38:55 +01:00
Katherine456719
38e553e418 Fix GH-18082: Memory leaks in fuzzer SAPI error paths
Closes GH-18081.
2025-03-16 16:37:59 +01:00
Kévin Dunglas
a191e7a4b1 Merge branch 'PHP-8.4'
* PHP-8.4:
  fix GH-8533: dynamic libphp linking on Mac
2025-03-12 08:59:20 +01:00
Kévin Dunglas
74a455fb11 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  fix GH-8533: dynamic libphp linking on Mac
2025-03-12 08:58:54 +01:00
Kévin Dunglas
009b5e2bfd fix GH-8533: dynamic libphp linking on Mac
Pass the -dynamiclib flag to libtool to build
a valid Mac dylib.

Closes GH-8533.
2025-03-12 07:40:02 +01:00
Tim Düsterhus
057ff3519d sapi/cli: Print non-default INI settings for --ini=diff (#17762)
This is a follow-up for php/php-src#17459, updating the command-line flag to
not modify the behavior of `--ini`.
2025-03-04 08:42:06 +01:00
Pascal Chevrel
ff88701b77 Fix GH-17956 Internal dev server 404 page is not responsive
Add a basic viewport html meta tag with responsive mode parameters
See: https://developer.mozilla.org/en-US/docs/Web/HTML/Viewport_meta_tag

Updated existing tests

close GH-17957
2025-03-03 12:05:00 +00:00
Niels Dossche
98e0501343 Drop support for -z CLI/CGI option
This functionality didn't actually work.
This was discussed on the mailing list [1] and no one objected.

[1] https://externals.io/message/126368

Closes GH-17883.
2025-03-03 08:21:56 +01:00
Christoph M. Becker
650086f3e6 Exclude unused functions from compilation units (GH-17686)
This avoids Clang complaining with `-Wunused-function`.

We also introduce the macro `PRELOAD_SUPPORT` for clarification.
2025-02-10 18:00:19 +01:00
Jakub Zelenka
bff0ec82a6 Merge branch 'PHP-8.4' 2025-02-08 12:08:19 +01:00