Commit graph

263 commits

Author SHA1 Message Date
Niels Dossche
32f0d24e1f soap: Get decompression function directly from function table and call it
The code is already looking up the entry in the function table anyway,
so might as well use it directly.
This simplifies the code and avoids a redundant lookup.
2025-07-03 20:28:38 +02:00
Niels Dossche
51149b65ad
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-18990, bug #81029, bug #47314: SOAP HTTP socket not closing on object destruction
  Fix leak when path is too long in ZipArchive::extractTo()
  curl: Remove incorrect string release on error
2025-07-02 18:47:53 +02:00
Niels Dossche
764154dc75
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-18990, bug #81029, bug #47314: SOAP HTTP socket not closing on object destruction
  Fix leak when path is too long in ZipArchive::extractTo()
  curl: Remove incorrect string release on error
2025-07-02 18:46:37 +02:00
Niels Dossche
69328ba304
Fix GH-18990, bug #81029, bug #47314: SOAP HTTP socket not closing on object destruction
Currently the resource is attached to the object and its refcount is
increased. This means that the refcount to the resource is 2 instead of
1 as expected. A refcount of 2 is necessary in the current code because
of how the error handling works: by using convert_to_null() the resource
actually goes to rc_dtor_func(), dropping its refcount to 1. So on error
the refcount is correct.
To solve the issue, let `stream` conceptually be a borrow of the
resource with refcount 1, and just use ZVAL_NULL() to prevent calling
rc_dtor_func() on the resource.

Closes GH-19001.
2025-07-02 18:44:05 +02:00
Niels Dossche
9859d837ca
Implement request #61105: Support Soap 1.2 SoapFault Reason Text lang attribute
This is on the border line of a bugfix and a new feature.
Anyway, this is necessary to fix compatibility with .NET clients.

Closes GH-18701.
2025-06-21 00:18:08 +02:00
Niels Dossche
83755748fd
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix memory leaks in php_http.c when call_user_function() fails
2025-05-24 21:54:45 +02:00
Niels Dossche
a44e3f442f
Fix memory leaks in php_http.c when call_user_function() fails
retval can be refcounted but is not destroyed.

Closes GH-18638.
2025-05-24 21:54:19 +02:00
Niels Dossche
ce3869b547
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix Soap leaking http_msg on error
2024-10-06 17:59:49 +02:00
Niels Dossche
a9dada29e7
Fix Soap leaking http_msg on error
Testing all cases is not so easy to do as we would need a server that
redirects from e.g. http to https while SSL is not available.

Closes GH-16254.
2024-10-06 17:58:28 +02:00
Niels Dossche
520fce5607
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix bug #73182: PHP SOAPClient does not support stream context HTTP headers in array form
2024-09-10 20:24:57 +02:00
Niels Dossche
72a2cbcc7f
Fix bug #73182: PHP SOAPClient does not support stream context HTTP headers in array form
This code is modelled after how `http_fopen_wrapper.c` does things,
which apparently is just looping over the array and handling each string
the same way as if we passed a header string directly.

Also fixes a potential crash in `php_sdl.c` but without adding support
for header arrays there (yet) because the code is untested.

Closes GH-15817.
2024-09-10 20:24:14 +02:00
Niels Dossche
7771ec07e5
Fix bug #61525: SOAP functions require at least one space after HTTP header colon
HTTP/1.1 does not require a single whitespace after the colon, and
SoapServer does implement HTTP/1.1. The header value is already correctly
whitespace-trimmed, so no behaviour change happens w.r.t. header values.

Closes GH-15793.
2024-09-08 10:42:30 +02:00
Niels Dossche
7d99a9cea1
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix bug #55639: Digest autentication dont work
2024-07-17 19:35:19 +02:00
Niels Dossche
911dc5b46c
Fix bug #55639: Digest autentication dont work
RFC 2617 and 7616 describe that for the "Authorization" header we should
not put the qop nor nc value inside quotes. This differs from the
WWW-Authenticate header, which may have been the source of the confusion
in the implementation. While the version with quotes seems to work fine
in some cases, clearly not all servers accept the non-standard form.
To fix the issue, simply removing the quotes of those two header fields
of the client request to be in line with the RFC suffices.

I refer further to example 3.5 in RFC 2617 and example 3.9.1 in
RFC 7616.

RFC 2617: https://datatracker.ietf.org/doc/html/rfc2617
RFC 7616: https://datatracker.ietf.org/doc/html/rfc7616

Closes GH-14328.
2024-07-17 19:23:10 +02:00
Gina Peter Banyard
1e7134f07f
ext/soap: Refactor implementation of in_domain() 2024-06-19 02:20:36 +01:00
Gina Peter Banyard
fd2d869642
Clean-up some more headers (#14416)
Remove unused headers (such as php_ini.h for extensions that don't define INI settings)
Use more specific headers when possible
2024-06-08 17:15:36 +01:00
Niels Dossche
ffe225d686
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix bug #76232: SoapClient Cookie Header Semicolon
2024-06-01 17:38:06 +02:00
Niels Dossche
1b1677a8f1
Fix bug #76232: SoapClient Cookie Header Semicolon
According to RFC 6265 [1] the cookies must be separated by "; " not ";",
and it must not end with ";".

[1] https://datatracker.ietf.org/doc/html/rfc6265

Closes GH-14406.
2024-06-01 17:37:30 +02:00
Niels Dossche
acfa564e72
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix bug #47925 again (#14348)
  Fix GH-14343: Memory leak in xml and dom (#14347)
2024-05-29 17:52:00 +02:00
Niels Dossche
ce7ed6e040
Fix bug #47925 again (#14348)
The naming of the userland functions is terrible and confused me.
gzdecode() is actually the function to decompress a gzip stream, and
gzuncompress() is the one to decompress a deflate stream...
See zlib.c to see the internal function -> type mapping.
2024-05-29 17:50:20 +02:00
Niels Dossche
8896bd3200
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix bug #47925: PHPClient can't decompress response (transposed uncompress methods?)
2024-05-27 19:24:18 +02:00
Niels Dossche
35e62e9b59
Fix bug #47925: PHPClient can't decompress response (transposed uncompress methods?)
The incorrect functions are being called to deal with incoming
compressed data.
gzip/x-gzip corresponds to gzuncompress(), while deflate corresponds to
gzinflate().

The existing code for gzip compression also plays with removing the
first 10 bytes (i.e. the gzip header) to pass it to the inflate
implementation but that doesn't always work properly due to trailer
data. Get rid of that entirely by using the correct functions.

Closes GH-14321.
2024-05-27 19:23:40 +02:00
Máté Kocsis
44b3cb2a13 Migrate SOAP URL resource to object
Related to https://wiki.php.net/rfc/resource_to_object_conversion and https://github.com/php/php-tasks/issues/6
2024-05-07 09:21:39 +02:00
Tim Düsterhus
97b3b4552d
random: Move CSPRNG API into php_random_csprng.h (#13290)
This allows consumers of just the CSPRNG to include a much smaller header. It
also allows to verify at a glance whether a source file might use non-secure
randomness.

This commit includes the new header wherever the CSPRNG is used, possibly
replacing the inclusion of php_random.h if nothing else is used, but also
includes it in the main php_random.h header for compatibility.

Somewhat related to 45f8cfaf10,
2b30f18708, and
b14dd85dca.
2024-02-01 19:09:35 +01:00
Niels Dossche
92e4e8bdf4 Fix #49278: SoapClient::__getLastResponseHeaders returns NULL if wsdl operation !has output
Instead of early exiting, process the headers if tracing is enabled, and
exit after that.

Closes GH-12609.
2023-11-06 19:04:15 +01:00
Pierrick Charron
38e4e58f42
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Update NEWS
  Update NEWS
  Fix GH-11382 add missing hash header for bin2hex
  Fix missing randomness check and insufficient random bytes for SOAP HTTP Digest
2023-06-06 18:07:19 -04:00
Pierrick Charron
a5b8bfce7c
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Update NEWS
  Fix GH-11382 add missing hash header for bin2hex
  Fix missing randomness check and insufficient random bytes for SOAP HTTP Digest
2023-06-06 18:01:56 -04:00
Remi Collet
0572448263
Fix GH-11382 add missing hash header for bin2hex 2023-06-06 17:56:19 -04:00
Niels Dossche
ac4254ad76
Fix missing randomness check and insufficient random bytes for SOAP HTTP Digest
If php_random_bytes_throw fails, the nonce will be uninitialized, but
still sent to the server. The client nonce is intended to protect
against a malicious server. See section 5.10 and 5.12 of RFC 7616 [1],
and bullet point 2 below.

Tim pointed out that even though it's the MD5 of the nonce that gets sent,
enumerating 31 bits is trivial. So we have still a stack information leak
of 31 bits.

Furthermore, Tim found the following issues:
* The small size of cnonce might cause the server to erroneously reject
  a request due to a repeated (cnonce, nc) pair. As per the birthday
  problem 31 bits of randomness will return a duplication with 50%
  chance after less than 55000 requests and nc always starts counting at 1.
* The cnonce is intended to protect the client and password against a
  malicious server that returns a constant server nonce where the server
  precomputed a rainbow table between passwords and correct client response.
  As storage is fairly cheap, a server could precompute the client responses
  for (a subset of) client nonces and still have a chance of reversing the
  client response with the same probability as the cnonce duplication.

  Precomputing the rainbow table for all 2^31 cnonces increases the rainbow
  table size by factor 2 billion, which is infeasible. But precomputing it
  for 2^14 cnonces only increases the table size by factor 16k and the server
  would still have a 10% chance of successfully reversing a password with a
  single client request.

This patch fixes the issues by increasing the nonce size, and checking
the return value of php_random_bytes_throw(). In the process we also get
rid of the MD5 hashing of the nonce.

[1] RFC 7616: https://www.rfc-editor.org/rfc/rfc7616

Co-authored-by: Tim Düsterhus <timwolla@php.net>
2023-06-06 17:53:45 -04:00
Go Kudo
4d8dd8d258
Implement Random Extension
https://wiki.php.net/rfc/rng_extension
https://wiki.php.net/rfc/random_extension_improvement
2022-07-19 10:27:38 +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
Nikita Popov
841d0b30eb Slightly clean up cookies handling
Make the property always an array with an empty array default.
Properly separate the array on modification to compensate.
2021-08-20 14:27:24 +02:00
Nikita Popov
de6cf68ac4 Fix missing string copy
I changed this to a zend_string_copy, but that's not correct in
this case, as we still append to the string below.

Also fix a test on 32-bit.
2021-08-20 14:15:23 +02:00
Nikita Popov
50484b59cd Move derefs into accessor macros
These derefs are mostly there to be defensive, but clutter the
code somewhat. Move them directly into the access macros.
2021-08-20 14:15:23 +02:00
Nikita Popov
e6c6abf6b4 Declare remaining SoapClient properties 2021-08-20 12:50:19 +02:00
Nikita Popov
aa4898ef2e Use separate property to request digit auth
Currently, _digest is used both to request that digest auth be
used (_digest == null) and to later store the _digest parameters.

This relies on the ability to distinguish between _digest being
null and it being not set, which is not present with declared
properties. (Well, technically it is, we could just leave it
uninitialized, but that would be non-idiomatic.)

Resolve this by splitting into separate _use_digest and _digest
properties.
2021-08-20 10:41:36 +02:00
Nikita Popov
018cb891cf Declare some SoapClient properties
This is only a subset of all properties for now (those without
underscore).
2021-08-19 16:15:41 +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
George Peter Banyard
84e12626e7 Use zend_string_equals() API instead of strcmp() in SOAP extension 2021-03-17 16:36:16 +00: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
e55a658115 Merge branch 'PHP-7.4'
* PHP-7.4:
  ext/soap: Compare Set-Cookie header case-insensitively
2020-09-17 10:31:48 +02:00
Nikita Popov
f0d2efbadc Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  ext/soap: Compare Set-Cookie header case-insensitively
2020-09-17 10:31:30 +02:00
Gabríel Arthúr Pétursson
efc52f1754 ext/soap: Compare Set-Cookie header case-insensitively
Closes GH-6143.
2020-09-17 10:31:06 +02:00
Matteo Beccati
cf3fb14679 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix #47021: SoapClient stumbles over WSDL delivered with "Transfer-Encoding: chunked"
2020-08-18 18:31:11 +02:00
Matteo Beccati
3877172411 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix #47021: SoapClient stumbles over WSDL delivered with "Transfer-Encoding: chunked"
2020-08-18 18:27:26 +02:00
Matteo Beccati
f7c43b8c72 Fix #47021: SoapClient stumbles over WSDL delivered with "Transfer-Encoding: chunked" 2020-08-18 18:10:39 +02:00
Gabriel Caruso
5d6e923d46
Remove mention of PHP major version in Copyright headers
Closes GH-4732.
2019-09-25 14:51:43 +02:00
Nikita Popov
d59aac58b3 Report errors from stream read and write operations
The php_stream_read() and php_stream_write() functions now return
an ssize_t value, with negative results indicating failure. Functions
like fread() and fwrite() will return false in that case.

As a special case, EWOULDBLOCK and EAGAIN on non-blocking streams
should not be regarded as error conditions, and be reported as
successful zero-length reads/writes instead. The handling of EINTR
remains unclear and is internally inconsistent (e.g. some code-paths
will automatically retry on EINTR, while some won't).

I'm landing this now to make sure the stream wrapper ops API changes
make it into 7.4 -- however, if the user-facing changes turn out to
be problematic we have the option of clamping negative returns to
zero in php_stream_read() and php_stream_write() to restore the
old behavior in a relatively non-intrusive manner.
2019-07-22 17:17:28 +02:00
Nikita Popov
290e520c03 Use ZEND_HASH_FOREACH APIs in a few more places 2019-07-16 12:20:16 +02:00