1
0
mirror of https://github.com/mariadb-corporation/mariadb-connector-c.git synced 2025-08-05 15:55:58 +03:00

258 Commits

Author SHA1 Message Date
Georg Richter
c07e50d940 Merge branch '3.1' into 3.3 2025-05-02 07:52:01 +02:00
Georg Richter
e44e3f6b25 CONC-771: Fix pipelining mode (mariadb_stmt_execute_direct)
If we are in pipeline mode (mariadb_stmt_execute_direct)
we don't need to return an error, if there is no or no more
data available: If the size of the buffer is a multiple
of 8192 packets might be already written and the buffer was
resetted afterwards.
2025-05-02 07:44:47 +02:00
Vladislav Vaintroub
126a753069 Remove workaround after MDEV-13492 was fixed.
SSL connection on Windows used retry logic initially, to "fix" MDEV-13492
This actual bug is now understood, and was fixed a while ago.
Remove the workaround now.
2025-04-22 10:18:48 +02:00
Georg Richter
4c9bc2b0f6 Merge branch '3.1' into 3.3 2025-02-27 07:52:35 +01:00
Georg Richter
aa240cd181 CONC-760: valid named pipe connection is closed
Fixed different behavior of pvio_is_alive (which was first used
with fix of CONC-589). Both for sockets and named pipe the function
now returns true if the connection is alive, otherwise false.
2025-02-27 07:48:58 +01:00
Georg Richter
4877093937 Workaround for MDEV-35935
If the server returns an error packet without error number
(and message) we set errno=CR_ERR_MISSING_ERROR_INFO (5026)
2025-02-11 11:28:56 +01:00
Kristian Nielsen
2381127b11 CONC-473: mysql_real_connect_start() stack overrun with mdns hostname
Increase the default stack size for co-routines to 256 kByte. It was 60
kByte, which was too small for glibc getaddrinfo() when using mdns.

Signed-off-by: Kristian Nielsen <knielsen@knielsen-hq.org>
2025-02-06 00:24:28 +01:00
Sergei Golubchik
2d56f340c4 Merge branch '3.1' into 3.3 2025-01-24 14:52:35 +01:00
Sergei Golubchik
836db56372 memory leaks after CONC-589, e09e24e8
we cannot just set `mysql->net.pvio= NULL`
we need to free(net->pvio) first.
And not protect `free(net->buff)` with `if (mysql->net.pvio)`.
2025-01-24 14:42:37 +01:00
Georg Richter
57ce0ce3c7 Merge branch '3.1' into 3.3 2025-01-15 08:00:19 +01:00
Georg Richter
e09e24e890 CONC-589: First query fails after reconnect
If automatic reconnect is enabled (MYSQL_OPT_RECONNECT) it is
mandatory to check if the connection/socket is still alive before
sending a command to the server (unless the command is COM_QUIT).
2025-01-15 07:26:18 +01:00
Georg Richter
12a7054194 Partial revert of 1a2ed3f67a
Since Item_result enumerations are also used by MariaDB server, we
moved them back to mariadb_com.h.
Item_result is not used in Connector/C 3.3 and above for replication
api.
2024-12-22 11:00:12 +01:00
Georg Richter
19495f1cdd Fix logical error in parse_connection_string
removed dead code (in_curly_brace is always true)
2024-12-19 11:14:19 +01:00
Georg Richter
d90e911ef6 Merge branch '3.1' into 3.3 2024-12-12 10:43:07 +01:00
Georg Richter
6bf9557d00 CONC-709: Fix crash when sending NULL_LENGTH in field description
Instead of checking the lengths given by two offsets, we have to
check if NULL_LENGTH was sent before (and return an error).
2024-12-12 10:40:30 +01:00
Georg Richter
294b933606 CONC-708: buffer over-/underflow in ma_read_ok_packet
Added a helper function ma_check_buffer_bounaaries which
checks possible boffer over- or underflows when processing
ok packet.^
2024-12-10 08:01:37 +01:00
Georg Richter
16e5b88bab MYSQL_OPT_ZSTD_COMPRESSION_LEVEL fixes:
Follow up for commit e633858c9e:
- Fixed ASAN bug (int to char conversion)
- Allow to retrieve zstd compression level via mysql_get_optionv()
2024-12-10 05:18:08 +01:00
Georg Richter
e633858c9e Merge pull request #261 from markus456/3.3-zstd-compression-level
Add configurable zstd compression level
2024-12-09 22:22:08 +01:00
Georg Richter
136d295d02 Merge branch '3.1' into 3.3 2024-12-09 19:32:13 +01:00
Georg Richter
554893c269 CONC-711: Ubsan and ASAN fixes
- fixed write functions in my_auth.c
- fixed misalignment error when obtaining data via
  option MARIADB_OPT_USERDATA (mysql_get_optionv).
2024-12-09 19:28:10 +01:00
Georg Richter
bdc66d6b8f Fix for CONC-703:
If connect failed and no error was set (apparently this happens
sometimes on Mac) we now set error to CR_SERVER_LOST.
2024-11-27 07:48:27 +01:00
Markus Mäkelä
a2213b89d4 Add MYSQL_OPT_ZSTD_COMPRESSION_LEVEL
The compression level was always hard-coded to 3.
2024-11-07 06:51:57 +02:00
Georg Richter
6635e4bdd6 Fix for CONC-735
If a reconnect occurs, we need to check if mysql->options.host was
already set and pass NULL instead of the previous host name.
2024-10-22 13:26:50 +02:00
Georg Richter
486ce75d64 CONPY-704: parse_connection_string ignores empty string in last parameter
1) Fix check if end was reached (<= instead of <), so last parameter will
not be ignored in case it is an empty string.

2) Empty strings will be passed as NULL`in _mariadb_set_conf_option.
2024-06-11 16:00:22 +02:00
Georg Richter
e69af190c3 Merge branch '3.1' into 3.3 2024-05-14 09:48:52 +02:00
Georg Richter
6bd5b6746f Follow up fix for CONC-696
According to next_thread_id() in mysqld.cc the
thread id is limited to 4 bytes. Thanks to Vlad
for pointing out
2024-05-14 09:45:51 +02:00
Georg Richter
f578e359e5 Merge branch '3.1' into 3.3 2024-05-13 16:09:47 +02:00
Georg Richter
d5394838fd CONC-696: Replace COM_PROCESS_KILL by KILL command
Since COM_PROCESS_KILL isn't supported by newer MySQL
versions.
2024-05-13 15:57:39 +02:00
Georg Richter
923a0092e3 Added missing support for restricted_auth in conf files 2024-05-08 11:45:14 +02:00
Georg Richter
ebe1949540 Fix for CONC-505:
Don't allow to specify unsupported client flags (like
CLIENT_DEPRECATE_EOF) as client flag in mysql_real_connect
api function.
2024-02-22 09:03:51 +01:00
Sergei Golubchik
f6e99af056 Revert "self-signed certificate verification", it's 3.4 feature
This reverts 395641549ac7..536d9e2b9e5b, in particular:

8dffd56936 MDEV-31857 enable MYSQL_OPT_SSL_VERIFY_SERVER_CERT by default
a99570c118 MDEV-31855 SSL cert validation protocol extension
9aa15e72a7 TLS fingerprint

and related commits
2024-02-19 11:16:26 +01:00
Sergei Golubchik
8dffd56936 MDEV-31857 enable MYSQL_OPT_SSL_VERIFY_SERVER_CERT by default
because the default value of every option is 0
(option and option.extension are bzero-ed to reset),
tls_verify_server_cert was renamed to tls_allow_invalid_server_cert
with the default value of 0, "do not allow".

API didn't change, it's still MYSQL_OPT_SSL_VERIFY_SERVER_CERT
2024-02-04 22:17:25 +01:00
Sergei Golubchik
a99570c118 MDEV-31855 SSL cert validation protocol extension
* extend the client auth plugin API with a new callback
* relax the plugin version check to allow load a plugin with the
  same major version, even if the minor versions differ
* implement the protocol extension:
  - don't abort at once if the certificate is self signed and
    no CA was explicitly specified
  - allow it if it passes fingerprint check
  - allow it if plugin has hash_password_bin callback, password was
    non-empty and the control hash matches server's
2024-02-04 22:17:25 +01:00
Sergei Golubchik
830d137387 don't use the output printf buffer as a %s parameter
followup for ebcb9eca29
2024-02-04 22:17:24 +01:00
Sergei Golubchik
77a2e6ac5d don't warn about the authenticity of client-side errors
they cannot be sent by the server (ma_net_safe_read() guarantees that)
so they all should be safe and not forged

also, use existing macros to check for error ranges, they are
sufficiently parenthesized to avoid compiler warnings (errors with -Werror)
about "you might want to add parentheses here"
2023-12-21 19:00:35 +01:00
Daniel Lenski
bd87353512 Remove unreachable code section
Based on Sergei Golubchik's question about this code section in
https://github.com/mariadb-corporation/mariadb-connector-c/pull/223#issuecomment-1773728383,
eventually culminating in the conclusion that it's literally impossible to
reach this code section based on the types and signedess of the variables
involved:
https://github.com/mariadb-corporation/mariadb-connector-c/pull/223#issuecomment-1854720364

All new code of the whole pull request, including one or several files
that are either new files or modified ones, are contributed under the
BSD-new license. I am contributing on behalf of my employer Amazon Web
Services, Inc.
2023-12-21 18:38:12 +01:00
Daniel Lenski
ebcb9eca29 [CONC-648] Do not trust error packets received prior to TLS handshake completion
MariaDB Connector/C does not distinguish [application-layer error
packets](https://mariadb.com/kb/en/err_packet) that it receives prior to TLS
handshake completion from those that it receives immediately after.

(A trivially modified server built from
https://github.com/dlenski/mariadb-server/commit/demonstration_of_CONC-648_vulnerability
can easily be used to demonstrate this.)

Pre-TLS error packet received from this trivially modified server. This packet
should NOT be trusted to actually originate from the server:

    $ mariadb --ssl --ssl-verify-server-cert -uUsername -pVerySecretPassword -h CONC-648.vuln.demo.server.com
    ERROR 1815 (HY000): Internal error: Client will accept this error as genuine even if running with --ssl --ssl-verify-server-cert, and even though this error is sent in plaintext PRIOR TO TLS HANDSHAKE.

Post-(TLS handshake) error packet received from a normal MariaDB server upon
an attempt to connect with incorrect credentials.  This error packet CAN be
trusted to actually originate from the server, assuming transitive trust in
the TLS protocol implementation and PKI-based certificate validation:

    $ mariadb --ssl --ssl-verify-server-cert -uUsername -pWrongPassword -h $NORMAL_MARIADB10.6.14_SERVER
    ERROR 1045 (28000): Access denied for user 'Username'@'A.B.C.D' (using password: YES)

This client behavior opens up MariaDB Connector/C clients to an extremely
straightforward [downgrade attack](https://en.wikipedia.org/wiki/Downgrade_attack).

An on-path or pervasive attacker can inject errors into MariaDB
client→server connections that are intended to be protected by TLS, and the
client has no clear mechanism to distinguish such errors from errors that
actually come from the server.

An attacker could easily use this to DOS a client, or even influence its
behavior.  For example, consider a client application which is configured…

1. To use TLS with server certificate validation
   (`--ssl --ssl-verify-server-cert`), and
2. To wait for a back-off period and then *retry* connection attempts if the server
   responds with `ER_CON_COUNT_ERROR` ("Too many connections") from the
   server, and
3. To give up and shut down if its connection attempts fail with
   `ER_ACCESS_DENIED_ERROR` ("Access denied for user"), on the assumption
   that this is due to an incorrect or expired password, and cannot be
   resolved without human intervention.

An attacker could completely disable the retry mechanism of this application
by intercepting connection attempts and replying with
`ER_ACCESS_DENIED_ERROR` packets.

This patch modifies MariaDB Connector/C so that if the client is configured
to use TLS, error packets received prior to the completion of the TLS
handshake are untrusted, and are changed to a generic `CR_CONNECTION_ERROR`.

    $ mariadb --ssl --ssl-verify-server-cert -uUsername -pVerySecretPassword -h CONC-648.vuln.demo.server.com
    ERROR 2002 (HY000): Received error packet before completion of TLS handshake. The authenticity of the following error cannot be verified:
    1815 - Internal error: Client will accept this error as genuine even if running with --ssl --ssl-verify-server-cert, and even though this error is sent in plaintext PRIOR TO TLS HANDSHAKE.

All new code of the whole pull request, including one or several files
that are either new files or modified ones, are contributed under the
BSD-new license. I am contributing on behalf of my employer Amazon Web
Services, Inc.
2023-12-21 18:38:12 +01:00
Daniel Lenski
4419abe71a Client should reject CLIENT-only error codes sent by the server
Per @vuvova in
https://github.com/mariadb-corporation/mariadb-connector-c/pull/223#issuecomment-1854720364:

> I don't think the client should accept client-side errors from the server
> at all.

If the server sends an error packet with error codes in the ranges
`CR_{MIN,MAX}_ERROR` (codes [2000, 2999]) or `CER_{MIN,MAX}_ERROR` (codes
[5000, 5999]), we will replace these with `CR_MALFORMED_PACKET`, rather than
propagating them to the client user.
2023-12-21 18:38:12 +01:00
Vladislav Vaintroub
463a50e973 Merge remote-tracking branch 'origin/3.1' into 3.3
# Conflicts:
#	include/ma_crypt.h
#	libmariadb/mariadb_lib.c
2023-09-21 23:45:35 +02:00
Georg Richter
9f37c27bc8 Fix for CONC-668:
Fix build error on 32-bit systems.
2023-09-18 16:05:00 +02:00
Georg Richter
3a255ee3ea Merge branch '3.1' into 3.3 2023-07-24 11:07:05 +02:00
Georg Richter
8ab517cbc1 Use OPT_SET_EXT_VALUE macro instead of assigning value
directly.
2023-07-13 10:58:15 +02:00
Georg Richter
45feebb99d Remove server certification verification
Since the server certification option is used by client
only, there is no need to have this flag in server and or
client capabilities. The server itself validates client
certificate depending on the user definition.
2023-07-13 09:30:33 +02:00
Marko Mäkelä
5af90f00ff Merge 3.1 into 3.3 2023-06-26 16:28:51 +03:00
Marko Mäkelä
d543bed61b Fix GCC 13 -Wmaybe-uninitialized 2023-06-26 10:59:14 +03:00
Georg Richter
85b7bde184 Merge branch '3.1' into 3.3 2023-05-02 18:01:34 +02:00
Georg Richter
a3bba4639f CONC-619: NULL pointer dereference in unpack_fields
Fixed NULL pointer dereference, thanks to Yury Chaikou which
reported this issue.
2023-05-02 17:59:18 +02:00
Georg Richter
dd8962a4b5 Merge branch '3.1' into 3.3 2023-04-25 15:08:28 +02:00
Georg Richter
0e452f66ac MariaDB Server detection fix
Use mariadb_connection() instead of checking 5.5.5 rpl hack
to detect if we are connected to a MariaDB Server.
2023-04-21 07:11:29 +02:00
Georg Richter
2000b06183 Replace SET_CLIENT_STMT_ERROR by stmt_set_error(). 2023-04-11 18:31:19 +02:00