1
0
mirror of https://github.com/mariadb-corporation/mariadb-connector-c.git synced 2025-07-29 08:01:25 +03:00

1021 Commits

Author SHA1 Message Date
e240810b38 fix: fixed the possible nullPointerAritheticOutOfMemory by using
SET_CLIENT_ERROR and return 1;
because jumping to the error label is not viable in this case as pos is
not initialized and it could raise more errors, this way we still handle
the error while not clashing with the original error handling
implementation
2025-07-17 09:15:04 +02:00
1edef5b207 fix: added a failsafe return 1; in case the malloc at 559 fails so that
we don't work with NULL
2025-07-17 09:14:53 +02:00
f2117d4225 fix: fixed the posibility of undefined behaviour of the strchr previously
at 252 if the strdup at 248 fails and thus returns NULL by
setting a client error signalling that the client ran out of
memory for easier communication of what exactly failed during the
loading of the plugins and why. Returning from the function just after
2025-07-17 09:14:53 +02:00
f72654e324 fix: fixed a memory leak due to the socket not being closed after
encountering an error by closing the socket before return
2025-07-17 09:14:53 +02:00
92a8b3b529 fix: fixed the posible read of NULL when strdup fails thus resulting in
rpl->filename being NULL by setting an error signalling that we ran out
of memory to ease the debugging of the mariadb_rpl_options function and make
it clearer if it ever fails because of this. Also added va_end in this case to
avoid the va_list (ap) leaking when we return from this function and
then returning 1 from the fucntion.
2025-07-17 09:14:53 +02:00
5ea5d7ae01 fix: fixed the order of the mariadb_free_rpl_event() and rpl_set_error()
calls to avoid using the rpl_even var after freeing it
2025-07-17 09:14:53 +02:00
40be423f08 Fix miscellaneous typos 2025-07-13 18:42:30 +03:00
c58dce932a Merge pull request #279 from grooverdan/static_analsis_fix
Static analysis fix
2025-07-10 09:04:02 +02:00
96b73e2052 Merge pull request #282 from grooverdan/win_get_password
get_tty_password(Windows) - CreateFile error
2025-07-09 11:52:15 +02:00
aebe28b8eb CONC-778: TLSv1.3 support for Windows Server 2022
Windows Server 2022 uses version number 10.0.20348, which is less than 10.0.22000.
Therefore, instead of checking for build numbers >= 22000 (which would exclude Server 2022),
we must check for build numbers >= 20348 to correctly include both Windows Server 2022
and Windows 11.

This is safe because TLSv1.3 was first supported in:
- Windows 11 (starting with build 22000)
- Windows Server 2022 (starting with build 20348)

Earlier versions did not support TLSv1.3:
- Windows 10 (up to build 19044)
- Windows Server 2019 (latest build 17763)
2025-06-07 15:32:44 +02:00
d226315ef8 get_tty_password(Windows) - CreateFile error
The Windows error condition for failing to open a file is
INVALID_HANDLE_VALUE is returned.
2025-05-29 16:40:50 +10:00
f431c6eaef CONC-776: enable rpl_set_error 2025-05-27 16:48:48 +10:00
bd233f8ac0 break; after return never reached 2025-05-27 16:48:39 +10:00
d5d330f82a mariadb_reconnect: reconnection may fail to allocate extensions
If this the case, tmp_mysql.extensions will be a null pointer
and the rest of the reconnection cannot continue.
2025-05-27 16:48:39 +10:00
b22b85bcdf mysql_init: early alloc failure not freed
Its possible for the net extensions allocation to
succeed but the other extensions to fail to allocate.

In this later case free the net alternatives explicitly
if we where going to free the entire allocation.
2025-05-27 16:48:39 +10:00
e2e5113a53 Fix my_context_[spawn|continue|yield] for aarch64 BTI
Fixes SIGILL in MariaDB Server "main.non_blocking_api" test case on
aarch64 processors supporting Branch Target Identification (BTI).

Branch Target Identification is a new aarch64 feature that prevents
jumping to arbitrary code locations that are not properly marked as
branch targets.

The "-mbranch-protection=standard" flag to GCC will enable code
generation using BTI. This is backwards compatible as the added
instructions are no-ops on older processors.

One example of where both "-mbranch-protection=standard" is enabled and
hardware supports it is with Amazon Linux 2023 and Graviton 4.

The symptom is the following mtr main.non_blocking_api failure:

  mysqltest got signal 4
  read_command_buf (0xaaaae6ae27a8): connect
  (con_nonblock,localhost,root,,test)

  conn->name (0xaaaae6b0c0b8):

  Attempting backtrace...
  stack_bottom = 0x0 thread_stack 0x3c000
  /usr/bin/mariadb-test(my_print_stacktrace+0x48)[0xaaaab6934088]
  bits/stdio2.h:79(signal_handler)[0xaaaab68f41a0]
  addr2line: 'linux-vdso.so.1': No such file
  linux-vdso.so.1(__kernel_rt_sigreturn+0x0)[0xffffa22bc830]
  /usr/bin/mariadb-test(my_context_spawn+0x74)[0xaaaab6914d84]

With GDB giving the information that SIGILL was on the perfectly legal
'mov' instruction:

  Program received signal SIGILL, Illegal instruction.
  0x0000aaaaaab44d84 in my_context_spawn (c=0xaaaaab07ada8, f=0xfffff7fed240, d=0x0) at
  mariadb1011-10.11.11-1.amzn2023.0.1.aarch64/libmariadb/libmariadb/ma_context.c:674
  674       __asm__ __volatile__
  (gdb) x/i$pc
  => 0xaaaaaab44d84 <my_context_spawn(my_context*, void (*)(void*),
  void*)+116>: mov      w0, #0x1                        // #1

The call sequence to get to this point is as follows:

  Breakpoint 1, my_context_spawn (c=0xaaaaab07ada8, f=0xaaaaaab38024
  <mysql_real_connect_start_internal(void*)>, d=0xffffffffc648) at
  libmariadb/ma_context.c:661
  661       register void *stack asm("x13") = c->stack_top;
  (gdb) c
  Continuing.

  Breakpoint 2, my_context_yield (c=0xaaaaab07ada8) at
  libmariadb/ma_context.c:843
  843       register const uint64_t *save asm("x19") = &c->save[0];

  Continuing from here leads to the SIGILL above.

The branch that ends up causing the SIGILL is the "br x11" instruction
in my_context_yield(). This is due to the branch being to a location
that is not marked as a branch target.

The fix is to ensure that these locations in the my_context aarch64
assembler are marked with "bti j" instructions so that the locations
that will be 'br'ed to are valid to be 'br'ed to.

Since older compilers don't know about the instruction, we need an ifdef
to define a string that has the raw opcode in it.

Fixes: d2285fb830
2025-05-13 14:53:23 -07:00
c07e50d940 Merge branch '3.1' into 3.3 2025-05-02 07:52:01 +02:00
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
02ceb06096 CONC-756: Update zlib to 1.3.1 2025-04-23 21:30:03 +02:00
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
55abb32038 Merge branch '3.1' into 3.3-merge 2025-04-20 10:16:30 +02:00
52c1eb4d75 CONC-766 Disable clang -Wcast-function-type-strict for makecontext
makecontext has a defined prototype in ucontext.h that
differs from its expected usage. Disable the clang
warning for this function call.
2025-04-10 14:59:12 +10:00
5b7df2276c CONC-764: Build error in ma_context.c on android
Some research show that X18 is mentioned as a platform-reserved
register on most non-linux platforms, including MacOS, Windows, and
FreeBSD. So only put it in the clobber list in Linux.

Note that the ma_context.c code does not itself use the X18 register
in any way. On platforms where X18 is reserved, the co-routine code
will preserve it. On platforms where co-routine code can modify X18,
it does not need to be preserved. Putting X18 in the clobber list is
only to avoid GCC itself generating code that requires that X18 is
preserved.

Signed-off-by: Kristian Nielsen <knielsen@knielsen-hq.org>
2025-04-03 07:54:22 +02:00
8e371bbe8e CONC-764: Build error in ma_context.c on android
X18 is a platform-reserved register on Android, not a callee-save
register. So it will not be touched by the spawned/resumed co-routine
and must not be included in the GCC asm clobber list on this platform.

Signed-off-by: Kristian Nielsen <knielsen@knielsen-hq.org>
2025-04-01 19:25:48 +02:00
28a1e4b599 Fix for CONC-762: Always set is_null and length in bind structure to avoid
msan errors
2025-03-31 11:02:35 +02:00
4c9bc2b0f6 Merge branch '3.1' into 3.3 2025-02-27 07:52:35 +01:00
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
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
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
77754f4d87 CONC-725: Fix compiler warning about uninitialized union member
Signed-off-by: Kristian Nielsen <knielsen@knielsen-hq.org>
2025-02-05 16:57:31 +01:00
879fcab625 Remove obsolete reference to my_context.c which was renamed to ma_context.c
Signed-off-by: Kristian Nielsen <knielsen@knielsen-hq.org>
2025-02-05 13:26:43 +01:00
003ea7e9de CONC-753: Compile error on .cfi_escape in builds with no unwind/cfi
Also CONC-754.

Depending on compiler options (eg. -fno-dwarf2-cfi-asm), the compiler may
not output .cfi_startproc / .cfi_endproc in generated assember, and this
causes a build error on the .cfi_escape directive put in my_context_spawn()
on systems with DWARF support.

Fix by using the proper preprocessor macro __GCC_HAVE_DWARF2_CFI_ASM to test
for .cfi_escape support, rather than crafted check for various compiler
brands and versions. Though this macro is only available in clang since
version 13.0.0, so unconditionally include the .cfi_escape in earlier clang
versions.

Thanks to Rainer Orth for the suggested fix.

Signed-off-by: Kristian Nielsen <knielsen@knielsen-hq.org>
2025-02-05 11:59:22 +01:00
2d56f340c4 Merge branch '3.1' into 3.3 2025-01-24 14:52:35 +01:00
232b563dc5 CONPY-739 don't use pow() to truncate an integer
it's
* generic power function, arbitrary floating-point arguments
* expensive
* returns double

while here we just need one of 1, 10, ..., 1000000.
2025-01-24 14:42:37 +01:00
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
57ce0ce3c7 Merge branch '3.1' into 3.3 2025-01-15 08:00:19 +01:00
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
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
2fd03c8242 coverity fix: remove whitespace 2024-12-19 11:47:18 +01:00
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
d90e911ef6 Merge branch '3.1' into 3.3 2024-12-12 10:43:07 +01:00
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
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
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
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
136d295d02 Merge branch '3.1' into 3.3 2024-12-09 19:32:13 +01:00
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
6d28fe89af Merge branch '3.1' into 3.3 2024-12-08 11:50:43 +01:00
af44fc5c5e CONC-748: Allow to set TLSv1.3 ciphers in GnuTLS
- Added TLSv1.3 ciphers to cipher map.
- Fixed retrieval of cipher suite: Since gnutls_cipher_suite_get_name
  supports only TLSv1.2 (and lower) cipher suites, we have to call
  gnutls_ciphersuite_get() (requires GnuTLS 3.7.4 or newer).
2024-12-08 11:27:32 +01:00
b522ed1a43 Merge branch '3.1' into 3.3 2024-11-27 15:58:51 +01:00