Commit graph

1808 commits

Author SHA1 Message Date
Peter Kokot
c2af281c0c
Use <winsock2.h> instead of legacy <winsock.h> (#19037)
This also omits defining unused HAVE_WINSOCK_H macro when building
ext/sockets.
2025-07-07 09:40:03 +02:00
Андрей Ковалёв
b871261c10
ext/mysqlnd/mysqlnd_auth.c: Add error handling for invalid public key size (#18663)
Reported-by: Pavel Nekrasov <p.nekrasov@fobos-nt.ru>

Signed-off-by: Andrey Kovalev <ded@altlinux.org>
Co-authored-by: Andrey Kovalev <ded@altlinux.org>
2025-06-02 11:55:25 +02:00
Kamil Tekiela
25f4f7982c
Drop unused variables (#18023) 2025-04-19 13:26:09 +01:00
Tim Düsterhus
633400bb56
mysqlnd: Make st_mysqlnd_stats.values a dynamic struct member (#18246)
This avoids another separate allocation.
2025-04-06 18:56:57 +02:00
Christoph M. Becker
aa76127d01
Address more Clang warnings (GH-17506)
We prefer clean solutions (such as declaring the proper type in the
first place, or introducing a portable format specifier) where easily
possible, but resort to casts otherwise.

We also port f1480ab14b.
2025-01-21 20:05:29 +01:00
Gina Peter Banyard
6ef58da59e
ext/mysqlnd: Refactor usage of strlcpy() (#17185)
The two calls that MySQLnd does to this handler all pass a buffer the same size as the error_msg field
Thus, we know that we can just memcpy the error message into the buffer.

See https://nrk.neocities.org/articles/not-a-fan-of-strlcpy for a rationale against the usage of `strlcpy()`
2024-12-28 23:00:08 +00:00
Christoph M. Becker
7e1d035077
Factor out SETUP_ZLIB_LIB() (GH-16798)
Note that this function is similar to `SETUP_OPENSSL`, but since the
zlib headers are not necessarily required, we append `_LIB`.

We are also more liberal regarding zlib(_a).lib, because
extensions requiring zlib are looking only for zlib.lib if ext/zlib has
been built as shared extension.  This is overly restrictive at best,
and actually makes no sense, since (a) we're not shipping shared zlib
builds for years, and (b) users could have a zlib.lib which is a static
build (they could even just rename zlib_a.lib to zlib.lib).
2024-11-27 18:35:34 +01:00
Jakub Zelenka
7c96af42b7
Merge branch 'PHP-8.3' into PHP-8.4 2024-11-20 11:14:04 +01:00
Jakub Zelenka
ffff27f734
Merge branch 'PHP-8.2' into PHP-8.3 2024-11-20 11:12:19 +01:00
Jakub Zelenka
d37a20c4a2
Fix MySQLnd possible buffer over read in auth_protocol 2024-11-20 11:06:53 +01:00
Jakub Zelenka
c595455300
Fix GHSA-h35g-vwh6-m678: Mysqlnd - various heap buffer over-reads
This fixes issues causing buffer over-read that leak heap content:
- RESP packet field default left over for COM_LIST
- RESP packet upsert filename
- OK packet message
- RESP packet for stmt row data
  - ps_fetch_from_1_to_8_bytes
  - ps_fetch_float
  - ps_fetch_double
  - ps_fetch_time
  - ps_fetch_date
  - ps_fetch_datetime
  - ps_fetch_string
  - ps_fetch_bit
- RESP packet for query row data (just possible overflow on 32bit)

It also adds various protocol tests using a new fake server.
2024-11-20 11:06:26 +01:00
Peter Kokot
41347f017b
[skip ci] Fix MYSQLND_HAVE_SSL preprocessor help texts
The MYSQLND_HAVE_SSL indicate that mysqlnd has extended SSL support
enabled through either OpenSSL when building with Autotools, and through
crypt32 library on Windows.

Fixes https://github.com/php/php-src/pull/15164#discussion_r1803834585

Closes GH-16474.
2024-11-10 20:41:06 +01:00
^_^
555b603d23
mysqlnd: support ER_CLIENT_INTERACTION_TIMEOUT (#13618) 2024-08-26 12:52:26 +09:00
Kamil Tekiela
195d59a83c Remove dead code 2024-08-25 10:32:50 +02:00
Kamil Tekiela
2446500d97 Remove unsupported mysqlnd options 2024-08-25 10:32:50 +02:00
Kamil Tekiela
c290996db6 Remove MYSQLI_TYPE_INTERVAL constant 2024-08-21 12:14:47 +02:00
Kamil Tekiela
a1ab846231
MySQL 9: Add support for VECTOR type (#15431) 2024-08-20 17:34:52 +02:00
Christoph M. Becker
57f02e2aba
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix GH-15432: Heap corruption when querying a vector
2024-08-20 15:45:42 +02:00
Christoph M. Becker
a3dbd39be0
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-15432: Heap corruption when querying a vector
2024-08-20 15:44:40 +02:00
Christoph M. Becker
b1211c1e4a
Fix GH-15432: Heap corruption when querying a vector
Since the mysqlnd result set is arena allocated, we must not simply
free it, but rather call the appropriate `free_result` method.

Co-authored-by: Kamil Tekiela <tekiela246@gmail.com>
2024-08-20 15:43:21 +02:00
Kamil Tekiela
6c7ff08920
Drop MYSQLI_CURSOR_TYPE_FOR_UPDATE & MYSQLI_CURSOR_TYPE_SCROLLABLE (#15486) 2024-08-19 13:54:40 +02:00
Kamil Tekiela
c316382acb
Remove MYSQLI_STMT_ATTR_PREFETCH_ROWS constant (#15485)
This feature was never implemented, and since the
beginning, using this constant with mysqlnd would
result in an error.
This feature was only available with libmysqlclient
which can no longer be used with mysqli.
There are no plans to implement it in the future.
2024-08-19 13:04:56 +02:00
Christoph M. Becker
4a77ce2022
Remove unnecessary Windows specific time formatting (GH-15474)
`gettimeofday()` is supported by PHP on Windows for ages; and generally
`localtime()` is supported on Windows for a long time.  As such, there
is no need for the Windows specific formatting code.

However, the general Windows caveat regarding `time_t` applies, namely
that it is usually `__time64_t`, unless `_USE_32BIT_TIME_T` is declared,
what we do for 32bit architectures, in which case it is `__time32_t`.
Now, `struct timeval` is imported from WinSock2.h, where the members are
declared as long (i.e. 32bit on both x86 and x64).  That means passing
a pointer to `tv_sec` to `localtime()` likely fails on x64, or at least
doesn't yield the desired result.  Therefore, we assign `tv_sec` to an
appropriate `time_t` variable, and also make sure that the `time_buffer`
is zero-terminated even if the `localtime()` call still fails.
2024-08-18 12:43:41 +02:00
Peter Kokot
b56f81cddc
Add configure phase dependencies to mysqlnd extension (#15380)
The hash extension is required in mysqlnd extension for using sha
functions when extended SSL is enabled (MYSQLND_HAVE_SSL).
2024-08-14 01:18:28 +02:00
Peter Kokot
cf6bbdfb0c
Autotools: Improve ftp and mysqlnd SSL configure options (#15164)
This makes the configure log messages and help text more intuitive what
is being enabled and when.
2024-08-03 22:13:36 +02:00
Peter Kokot
a1b45bb87a
Autotools: Sync PHP_SETUP_* M4 macros (#15117)
- arguments quoted
- MYSQLND_HAVE_SSL help text synced
2024-07-27 11:20:07 +02:00
Peter Kokot
6857c7c8d6
Autotools: Expand m4_normalize sooner (#15018)
Quoted m4_normalize will expand and change its argument later in the
macro call when M4 is processing the *.m4 sources. Without quotes the
already normalized string is passed to the macro directly. In these
specific cases generated configure script is the same. This is more for
consistency to have this synced and not repeat the pattern too much
in the future when copy/pasting. Note, that many AC_* macros require
similar behavior already (for example, AC_CHECK_FUNCS.)
2024-07-19 15:20:04 +02:00
Peter Kokot
42530c6543
Remove unused SMART_STR_PREALLOC (#14848) 2024-07-07 01:04:53 +02:00
Arnaud Le Blanc
11accb5cdf
Preferably include from build dir (#13516)
* Include from build dir first

This fixes out of tree builds by ensuring that configure artifacts are included
from the build dir.

Before, out of tree builds would preferably include files from the src dir, as
the include path was defined as follows (ignoring includes from ext/ and sapi/) :

    -I$(top_builddir)/main
    -I$(top_srcdir)
    -I$(top_builddir)/TSRM
    -I$(top_builddir)/Zend
    -I$(top_srcdir)/main
    -I$(top_srcdir)/Zend
    -I$(top_srcdir)/TSRM
    -I$(top_builddir)/

As a result, an out of tree build would include configure artifacts such as
`main/php_config.h` from the src dir.

After this change, the include path is defined as follows:

    -I$(top_builddir)/main
    -I$(top_builddir)
    -I$(top_srcdir)/main
    -I$(top_srcdir)
    -I$(top_builddir)/TSRM
    -I$(top_builddir)/Zend
    -I$(top_srcdir)/Zend
    -I$(top_srcdir)/TSRM

* Fix extension include path for out of tree builds

* Include config.h with the brackets form

`#include "config.h"` searches in the directory containing the including-file
before any other include path. This can include the wrong config.h when building
out of tree and a config.h exists in the source tree.

Using `#include <config.h>` uses exclusively the include path, and gives
priority to the build dir.
2024-06-26 00:26:43 +02:00
Peter Kokot
3cbf5aa63e
Normalize mysqlnd extension sources (#14654)
The m4_normalize() can simplify the list argument. It removes leading
and trailing spaces and tabs, sequences of backslash-then-newline, and
replaces multiple spaces, tabs, and newlines with a single space.
2024-06-25 19:33:51 +02:00
Peter Kokot
b12ccb319f
Add PHP_SETUP_ZLIB M4 macro (#14591)
This enables the zlib library (https://zlib.net/) from a single place to
match the minimum required version across the php-src. This provides a
possible simpler version bump in the future. Macro's 2nd and 3rd
arguments can pass additional actions whether zlib library is found or
not for the possible future adjustments in the ext/standard where also
zlib might be required.

Support for pkg-config was introduced in 1.2.3.1.
The minimum zlib version has been bumped to 1.2.3.1



* Bump minimum zlib version to 1.2.11

This is aligned with CentOS 8, which has 1.2.11 in the default packages.

* [skip ci] Move zlib version change to UPGRADING

This matches the OpenSSL style version change notice already done in
this file.
2024-06-21 15:05:34 +02:00
Niels Dossche
b1fd3477b2 mysqlnd: change uses of sprintf into snprintf 2024-06-14 08:12:03 -07:00
Niels Dossche
7c947b57b7
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Partially backport GH-13782 to stable branches
2024-05-30 21:02:03 +02:00
Niels Dossche
c815cdcfe7
Partially backport GH-13782 to stable branches
This partially backports that PR to stable branches as it has been in master
without reported problems so far.
It's only a partial backport because the stable branches don't have the
ZTS persistent resource fix that would fix shutdown crashes, i.e. the
code change in mysqlnd_vio's close_stream is not backported.

This is fully fixed on master.

Closes GH-14324.
Closes GH-10599.
2024-05-30 20:58:54 +02:00
Kamil Tekiela
73abf4fe93
Merge branch 'PHP-8.3'
* PHP-8.3:
  Clear mysql error in fetch_into
2024-05-17 13:16:59 +02:00
Kamil Tekiela
05efcc245e
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Clear mysql error in fetch_into
2024-05-17 13:13:18 +02:00
Kamil Tekiela
a59868aef8
Clear mysql error in fetch_into
Closes GH-14256
2024-05-17 13:08:42 +02:00
Peter Kokot
b5b9c13c3d
Add missing MYSQLND_SHARED_LIBADD substitution (#14228)
This is used in Makefile when building mysqlnd as shared to get zlib and
crypto libraries linked in the mysqlnd.so (-lz -lcrypto). For static
build these are in the resulting binary like before.
2024-05-17 12:21:11 +02:00
Peter Kokot
44ed17cab5
Replace configure option --with-openssl-dir (#14028)
This is a leftover from the refactoring of the --with-openssl-dir option
that once accepted the path to OpenSSL but wasn't renamed back then.

Instead of --with-openssl-dir, SSL support in ext/ftp and ext/mysqlnd
can be enabled implicitly when building with ext/openssl enabled
(--with-openssl) or explicitly by using new separate configure options
--with-ftp-ssl and --with-mysqlnd-ssl.
2024-05-13 22:54:54 +02:00
Niels Dossche
43cbeb3bf0
Add an assertion for certainty 2024-04-21 16:07:40 +02:00
Niels Dossche
bb8234d2bd
Use php_stream_auto_cleanup() consistently 2024-04-21 16:07:40 +02:00
Niels Dossche
0b69c3aea4
Fix crash in shutdown when using a named pipe with a persistent mysqli connection
The code originally posted in GH-10599 triggers the bug for
non-persistent connections, but changing the host to `p:.` reveals that
there is also a crash bug for persistent connections.
2024-04-21 16:07:40 +02:00
Niels Dossche
a20d9d72b1
Factor common code out into mysqlnd_fixup_regular_list()
This prevents the code from getting desynced again, which was the reason
for the leak of GH-10599.
2024-04-21 16:07:40 +02:00
Niels Dossche
319fb50eca
Fix memory leak in mysqlnd_vio::open_pipe
This fixes the memory leak part of GH-10599.
2024-04-21 16:07:40 +02:00
Niels Dossche
06b87f912b
Remove broken hack in mysqlnd_vio::close_stream
What happens is that the persistent network stream resource gets freed, yet
stays inside EG(persistent_list). This causes a crash on shutdown when the
persistent list is getting cleared, as the engine will try to free the network
stream again.

The code in close_stream gets confused between persistent vs
non-persistent allocations when EG(active) is false.
This code was introduced in c3019a1 to fix crashes when the persistent list
gets destroyed before module shutdown is called. This is indeed a potential
problem that was fixed on the master branch in 5941cda.

This fixes the crash reason of GH-10599.
2024-04-21 16:07:39 +02:00
Jakub Zelenka
d24086b7ba
Merge branch 'PHP-8.3' 2024-04-12 11:04:41 +01:00
Jakub Zelenka
fbcad699cb
Merge branch 'PHP-8.2' into PHP-8.3 2024-04-12 10:57:42 +01:00
Jakub Zelenka
3b93f13199
Revert "ext/mysqlnd: support ER_CLIENT_INTERACTION_TIMEOUT"
This reverts commit 5035b85090.

This broke Doctrine DBAL tests - more discussion in GH-13618.
2024-04-12 10:56:09 +01:00
Kamil Tekiela
72f94a127f
Merge branch 'PHP-8.3'
* PHP-8.3:
  ext/mysqlnd: support ER_CLIENT_INTERACTION_TIMEOUT
2024-04-10 13:37:36 +02:00
Kamil Tekiela
acf9047346
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  ext/mysqlnd: support ER_CLIENT_INTERACTION_TIMEOUT
2024-04-10 13:35:14 +02:00