Commit graph

683 commits

Author SHA1 Message Date
Ben Ramsey
d854a54b5f
Merge branch 'PHP-8.3' into PHP-8.4 2024-09-26 14:24:13 -05:00
Ben Ramsey
6d99ccc268
Merge branch 'PHP-8.2' into PHP-8.3 2024-09-26 14:13:00 -05:00
Ben Ramsey
c259c9f3f6
Merge branch 'PHP-8.1' into PHP-8.2 2024-09-26 13:13:46 -05:00
Niels Dossche
c1c14c8a0f
Fix GHSA-94p6-54jq-9mwp
Apache only generates REDIRECT_STATUS, so explicitly check for that
if the server name is Apache, don't allow other variable names.
Furthermore, redirect.so and Netscape no longer exist, so
remove those entries as we can't check their server name anymore.

We now also check for the configuration override *first* such that it
always take precedence. This would allow for a mitigation path if
something like this happens in the future.
2024-09-23 11:24:26 +01:00
Niels Dossche
4b9cd27ff5
Fix GHSA-p99j-rfp4-xqvq
It's no use trying to work around whatever the operating system and Apache
do because we'll be fighting that until eternity.
Change the skip_getopt condition such that when we're running in
CGI or FastCGI mode we always skip the argument parsing.
This is a BC break, but this seems to be the only way to get rid of this
class of issues.
2024-09-23 11:24:19 +01:00
Calvin Buckley
afc5738154
Show build provider and unify version information printing (#14657)
* Show build provider information in "php -v"

Vendors such as distributions can set the `PHP_BUILD_PROVIDER`
variable, that gets printed in phpinfo. However, I find that users check
`php -v` more often than phpinfo to see what PHP they're running. The
problem with this is that it does not show that build provider
information.

This change makes the build provider information printed on an
additional line of the version information.

* Put on same line so it works with or without env var

Unbreaks build without PHP_BUILD_PROVIDER set.

* change wording in provider version text

better grammatically; many different possibilities here though

* Unify SAPI version printing

This makes it so that all of the SAPIs share the same code for printing
version information. This is useful in case of any future changes to the
version information, such as i.e. adding build provider to the output.

* Make include for php_print_version explicit

* Preserve phpdbg version and output channel

php_printf doesn't have same semantics, as phpdbg_out could be on a
different output than stdout/err. Also add the phpdbg version (in case
it differs from PHP's, to keep similar output before this PR)

* remove size variables

we don't use them and CI doesn't like unused variables

* Fix format string insecurity
2024-08-12 23:24:41 -03:00
Ilija Tovilo
20d8151b35
Add cachegrind support for php-cgi warmups (#14952)
Cachegrind supports cg_annotate --diff, which makes it much easier to compare
the performance of two patches.

Co-authored-by: Peter Kokot <peterkokot@gmail.com>
2024-07-14 19:53:16 +02:00
Peter Kokot
2ebef11e83
Update http links to https and sync www.php.net URLs (#14854) 2024-07-07 04:23:08 +02:00
Peter Kokot
cf3b9fca8f
Sync #if/ifdef/defined (-Wundef) (#14623)
These are either define (to value 1) or undefined:
- __GNUC__
- DBA_CDB_BUILTIN
- DBA_GDBM
- HAVE_FORK
- HAVE_PUTENV
- HAVE_SETENV
- HAVE_SYS_SELECT_H
- HAVE_SYS_SOCKET_H
- HAVE_SYS_WAIT_H
- HAVE_UNSETENV
- RFC3678_API
- ZEND_ENABLE_ZVAL_LONG64
- ZTS

Follow-up of GH-5526
2024-06-24 19:37:07 +02:00
Peter Kokot
338be9dd9c
Fix PHP_DEBUG condition in cgi SAPI (#14620)
PHP_DEBUG is always defined, either to 0 or 1. This matches the
fpm_main.c code with similar check even though it was not executed for
a while.
2024-06-21 20:59:34 +02:00
Peter Kokot
61a0e3bd19
Sync HAVE_OPENSSL* symbols (#14333)
This syncs few inconsistencies between the Windows and Autotools build
systems:
- HAVE_OPENSSL_EXT is now defined in the same style on both systems
  (undefined - extension is not available, defined to 1 - extension is
  available)
- HAVE_OPENSSL removed as it was only defined on Windows
2024-06-11 19:18:19 +02:00
Peter Kokot
a82d86479c
Replace WIN32 conditions with _WIN32 or PHP_WIN32 (#14462)
* Replace WIN32 conditions with _WIN32 or PHP_WIN32

WIN32 is defined by the SDK and not defined all the time on Windows by
compilers or the environment. _WIN32 is defined as 1 when the
compilation target is 32-bit ARM, 64-bit ARM, x86, or x64. Otherwise,
undefined.

This syncs these usages one step further.

Upstream libgd has replaced WIN32 with _WIN32 via
c60d9fe577

PHP_WIN32 is added to ext/sockets/sockets.stub.php as done in other
*.stub.php files at this point.

* Use PHP_WIN32 in ext/random

* Use PHP_WIN32 in ext/sockets

* Use _WIN32 in xxhash.h as done upstream

See https://github.com/Cyan4973/xxHash/pull/931

* Update end comment with PHP_WIN32
2024-06-10 21:59:41 +02:00
Peter Kokot
84a0da1574
Sync #if/ifdef/defined (#14508)
This syncs CPP macro conditions:
- _WIN32
- _WIN64
- HAVE_ALLOCA_H
- HAVE_ALPHASORT
- HAVE_ARPA_INET_H
- HAVE_CONFIG_H
- HAVE_DIRENT_H
- HAVE_DLFCN_H
- HAVE_GETTIMEOFDAY
- HAVE_LIBDL
- HAVE_POLL_H
- HAVE_PWD_H
- HAVE_SCANDIR
- HAVE_SYS_FILE_H
- HAVE_SYS_PARAM_H
- HAVE_SYS_SOCKET_H
- HAVE_SYS_TIME_H
- HAVE_SYS_TYPES_H
- HAVE_SYS_WAIT_H
- HAVE_UNISTD_H
- PHP_WIN32
- ZEND_WIN32

These are either undefined or defined to 1 in Autotools and Windows.

Follow up of GH-5526 (-Wundef).
2024-06-09 14:23:41 +02:00
Ben Ramsey
bda372fc6c
Merge branch 'PHP-8.3' 2024-06-05 01:11:59 -05:00
Ben Ramsey
e4453dcbd2
Merge branch 'PHP-8.2' into PHP-8.3 2024-06-05 01:11:30 -05:00
Ben Ramsey
8aff5b49c3
Merge branch 'PHP-8.1' into PHP-8.2 2024-06-05 01:10:47 -05:00
Niels Dossche
9382673148
Fix GHSA-3qgc-jrrr-25jv
The original code is error-prone due to the "best fit mapping" that
happens with the argument parsing but not with the query string.
When we get a non-ASCII character, try to remap it and see if it becomes
a hyphen.

An alternative approach is to create a custom main `wmain` receiving
wide-character variations that does the ANSI transformation with the
best-fit mapping, but that's more error-prone and could cause unexpected
breakage.

Another alternative was just don't doing this check altogether and
always check for `cgi || fastcgi` instead, but that breaks real-world
use-cases.
2024-06-05 00:29:19 -05:00
Niels Dossche
a95d001a8a
Change calls to setmode to _setmode (#14220)
setmode is the deprecated alias of _setmode [1].

[1] https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/posix-setmode?view=msvc-170
2024-05-13 22:08:24 +02:00
David Carlier
0a134e5d85
Merge branch 'PHP-8.3' 2024-05-01 14:00:03 +01:00
David Carlier
ff6e3b6f76
Merge branch 'PHP-8.2' into PHP-8.3 2024-05-01 13:59:10 +01:00
David Carlier
74843947f4
sapi/cgi: fix buffer limit on windows.
MSDN recommends dropping the deprecated `read` in favor of `_read`.
Also, the buffer size limit is INT_MAX.

Close GH-14022
2024-05-01 13:58:53 +01:00
David CARLIER
c2553a28e1
sapi/fcgi: update listen queue size handling. (#13939)
the default backlog does not necessarily need to be higher than 128,
however for systems like haiku it s mor benefitial to be actually lower.
2024-04-10 23:46:41 +01:00
Cristian Rodríguez
eb238577f1
cgi: tidy up fastcgi_cleanup signal handler (#13026)
* signal handlers can only touch global volatile sig_atomic_t variables.
* fastcgi_cleanup is static
* structs sigaction are static
* A signal handler cannot call exit() because it is not async signal safe,
  call _exit instead.
2024-02-02 18:10:34 +01:00
Niels Dossche
6edbbc1c3e Implement GH-12385: flush headers without body when calling flush()
Closes GH-12785.
2023-12-01 17:15:57 +01:00
Niels Dossche
f16b34f1d0 Implement GH-10024: support linting multiple files at once using php -l
This is supported in both the CLI and CGI modes. For CLI this required
little changes.

For CGI, the tricky part was that the options parsing happens inside the
loop. This means that options passed after the -l flag were previously
simply ignored. As we now re-enter the loop we would parse the options
again, and if they are handled but don't set the script name, then CGI
will think you want to read from standard in. To keep the same "don't
parse options" behaviour I simply wrapped the options handling inside an
if.

Closes GH-10024.
Closes GH-10710.
2023-07-05 15:20:36 +02:00
Ilija Tovilo
24cc40207d
Benchmarking mean (#11085)
* Use 50 runs and calculate mean

* Don't validate timestamps

* Don't profile PHP startup and shutdown in cgi with valgrind
2023-04-15 23:14:20 +02:00
Christoph M. Becker
c8955c078a
Revert GH-10220
Cf. <https://github.com/php/php-src/pull/10220#issuecomment-1383739816>.

This reverts commit ecc880f491.
This reverts commit 588a07f737.
This reverts commit f377e15751.
This reverts commit b4ba16fe18.
This reverts commit 694ec1deea.
This reverts commit 6b34de8eba.
This reverts commit aa1cd02a43.
This reverts commit 308fd311ea.
This reverts commit 16203b53e1.
This reverts commit 738fb5ca54.
This reverts commit 9fdbefacd3.
This reverts commit cd4a7c1d90.
This reverts commit 928685eba2.
This reverts commit 01e5ffc85c.
2023-01-16 12:27:33 +01:00
Max Kellermann
6b34de8eba sapi/*: add missing includes 2023-01-10 14:19:03 +00:00
Michael Voříšek
bd3cd6a41a
Fix unstable sapi test, fix GH-9140 (#9184) 2022-08-04 22:35:44 +01:00
George Peter Banyard
5ba6ecd523
Minor refactoring of main/main.c and TSRM (#8608) 2022-05-24 08:34:55 +01:00
George Peter Banyard
2ecd46f48f
Initialise zend_stat_t to fix MSAN build 2022-05-22 16:06:27 +01:00
George Peter Banyard
b5db594fd2
Refacto php_module_startup() (#8303)
It only ever uses at most 1 additional modules
2022-04-27 23:07:11 +01:00
Max Kellermann
d87ba95acd
sapi/*: move duplicate "--define" code to library 2022-04-18 16:52:08 +02:00
Christoph M. Becker
796511f324
Fix php-cgi name in usage info
Cf. <https://github.com/php/doc-en/issues/1312#issuecomment-1008214821>.

Closes GH-7916.
2022-01-10 18:21:09 +01:00
Dmitry Stogov
90b7bde615 Use more compact representation for packed arrays.
- for packed arrays we store just an array of zvals without keys.
- the elements of packed array are accessible throuf as ht->arPacked[i]
  instead of ht->arData[i]
- in addition to general ZEND_HASH_FOREACH_* macros, we introduced similar
  familied for packed (ZEND_HASH_PACKED_FORECH_*) and real hashes
  (ZEND_HASH_MAP_FOREACH_*)
- introduced an additional family of macros to access elements of array
  (packed or real hashes) ZEND_ARRAY_ELEMET_SIZE, ZEND_ARRAY_ELEMET_EX,
  ZEND_ARRAY_ELEMET, ZEND_ARRAY_NEXT_ELEMENT, ZEND_ARRAY_PREV_ELEMENT
- zend_hash_minmax() prototype was changed to compare only values

Because of smaller data set, this patch may show performance improvement
on some apps and benchmarks that use packed arrays. (~1% on PHP-Parser)

TODO:
    - sapi/phpdbg needs special support for packed arrays (WATCH_ON_BUCKET).
    - zend_hash_sort_ex() may require converting packed arrays to hash.
2021-11-03 15:18:26 +03:00
Christoph M. Becker
1f9b044c80
Merge branch 'PHP-8.0'
* PHP-8.0:
  Fix #80849: HTTP Status header truncation
2021-07-15 19:16:21 +02:00
Christoph M. Becker
bb4dbbc150
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fix #80849: HTTP Status header truncation
2021-07-15 19:13:58 +02:00
Christoph M. Becker
a054ef2aad
Fix #80849: HTTP Status header truncation
While truncating the contents of a header is okay, we must never omit
the trailing CRLF.

Closes GH-7238.
2021-07-15 19:10:53 +02:00
Patrick Allaert
aff365871a Fixed some spaces used instead of tabs 2021-06-29 11:30:26 +02:00
KsaR
01b3fc03c3
Update http->https in license (#6945)
1. Update: http://www.php.net/license/3_01.txt to https, as there is anyway server header "Location:" to https.
2. Update few license 3.0 to 3.01 as 3.0 states "php 5.1.1, 4.1.1, and earlier".
3. In some license comments is "at through the world-wide-web" while most is without "at", so deleted.
4. fixed indentation in some files before |
2021-05-06 12:16:35 +02:00
Josh Soref
462da6e09c Fix spelling and grammar mistakes
This PR corrects misspellings identified by the check-spelling action.

The misspellings have been reported at jsoref@b6ba3e2#commitcomment-48946465

The action reports that the changes in this PR would make it happy: jsoref@602417c

Closes GH-6822.
2021-04-13 12:09:37 +02:00
Nikita Popov
4ce5d2ea88 Add known strings for jit autoglobals
We always create interned strings for all autoglobals anyway, so
we might as well add known strings to make them more widely usable.
2021-04-09 15:37:59 +02:00
Dmitry Stogov
c732ab400a Change Zend Stream API to use zend_string* instead of char*.
This allows to eliminate re-calculation of string lenght and hash value.
See the detailed list of changes in UPGRADING.INTERNALS.
2021-03-16 20:31:36 +03:00
Nikita Popov
3e01f5afb1 Replace zend_bool uses with bool
We're starting to see a mix between uses of zend_bool and bool.
Replace all usages with the standard bool type everywhere.

Of course, zend_bool is retained as an alias.
2021-01-15 12:33:06 +01:00
Nikita Popov
c97da0f819 Revert "Fix bug #64865: Use CONTEXT_DOCUMENT_ROOT for scanning dir tree"
This reverts commit 98bfad738a.

This doesn't work well in some setups, see bug #80113 and GH-5051.
Reverting this for now.
2020-10-19 11:23:00 +02:00
Máté Kocsis
f328594072 Add stubs for SAPIs
Closes GH-5295.
2020-07-10 14:20:18 +02:00
Max Semenik
2b5de6f839
Remove proto comments from C files
Closes GH-5758
2020-07-06 21:13:34 +02:00
Nikita Popov
f89d84d622 Better leak fix for cgi -s / -w
We also need to go through request shutdown. The naming is a bit
confusing, but it's fine to go through fastcgi_request_done even
if not using fastcgi. Whether we loop or not is checked separately.
2020-06-26 11:07:55 +02:00
Nikita Popov
a1c6a7a3f2 Fix leaks in cgi strip/highlight mode 2020-06-25 16:06:33 +02:00
twosee
88355dd338 Constify char * arguments of APIs
Closes GH-5676.
2020-06-08 10:38:45 +02:00