CONC-821 in Connector/C 3.3.21 no longer resets *length for string
binds, so for NULL values the length array in append_stmt_result()
stayed uninitialized. Zero-fill it on allocation.
With --ps-protocol, mysqltest runs a SELECT a second time and compares
the results. The regex ps2_re only matched a leading SELECT, so a
statement starting with '(' was executed only once.
Allow any number of '(', each optionally followed by spaces, before
SELECT in ps2_re.
What was wrong:
The mysqltest expression evaluator did signed arithmetic without
checking that the result fits in long long. Boundary expressions
triggered undefined behavior or returned mathematically wrong wrapped
values, e.g. -9223372036854775808 / -1 gave -9223372036854775808, and
unsigned 18446744073709551615 + 1 gave 0.
How it is fixed:
Check unary minus, +, -, *, / and abs() before evaluating and die() with
an "Evaluation error: ... overflow" message when the result is not
representable in 64 bits. Unsigned +, - and * are checked the same way;
an unsigned difference that is negative but fits in long long is
returned as a signed value. A negative signed operand mixed with an
unsigned one is rejected instead of being silently converted. Valid
boundary results are kept: -9223372036854775808 % -1 = 0 and
-4611686018427387904 * 2 = -9223372036854775808. Unary minus on an
unsigned value still wraps, as conv(-~0, ...) in
main.mysqltest_string_functions relies on it.
How it is tested:
main.mysqltest_expression_evaluation: the former wrapping cases now
expect an error, and signed and unsigned overflow cases were added.
main.mysqltest, main.mysqltest_string_functions and the other tests
using $() pass, also with --ps-protocol.
`--sync_with_master` uses `get_string()`,
which has `$variable` support, but it only uses the read buffer,
which is written with the unexpanded string and not the variable value.
Reviewed-by: KhaledR57 <khaled57.dev@gmail.com>
Ask users to give MariaDB a star by having an extra line in the MariaDB
client prompt:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is X
Server version: Y
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Help others discover MariaDB. Star it on GitHub: https://github.com/MariaDB/server
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
Test file updated with:
nano --noconvert --nonewlines mysql-test/main/mysql-interactive.result
This change is similar to 346c7afe9b
applied on 'main', but without the SERVER_MATURITY_LEVEL check in order
to have this text visible in stable releases and actually help get the
GitHub star count up, and without the server log entry.
The --gtid-strict-mode option in mariadb-binlog was introduced in MDEV-4989
with a default of ON. This causes mariadb-binlog to refuse to display
events when it encounters out-of-order GTIDs, which commonly happens
when replaying a remote binlog into a server and then reading back the
resulting local binlog files.
This is overly restrictive for a diagnostic/display tool. While the
server's gtid_strict_mode makes sense as a safety mechanism, applying
the same strict validation by default in the client tool prevents users
from even inspecting problematic binlog files.
Change the default to OFF so that mariadb-binlog processes binlog files
without erroring on out-of-order GTIDs by default. Users who want strict
validation can still explicitly pass --gtid-strict-mode.
Added regression test binlog.mdev_29803 that verifies:
- Default (OFF): reading binlog files with replayed events succeeds
- Explicit --gtid-strict-mode: still produces the expected error
WEXITSTATUS() only produces a meaningful value when the process
exited normally. If the command was killed by a signal, it silently
returned status 0, hiding the failure. Check WIFEXITED/WIFSIGNALED
and map signal deaths to the shell's 128+signal convention.
func_hex() passed every argument through convert_base_helper(), which
parses the argument as a base 10 number. A string argument therefore
died with "invalid number 'abc' for base 10" instead of being converted.
HEX() is the only one of the base conversion functions that accepts a
string. In the server BIN() and OCT() are built as Item_func_conv() with
fixed bases and are numeric only, while HEX() has a dedicated Item with
a separate string path, because HEX() is the counterpart of UNHEX() and
has to serialise bytes.
Dispatch on the argument type: numeric arguments keep the existing
CONV(N, 10, 16) behaviour, string arguments are converted byte by byte
with String::set_hex(), which is the same call the server uses in
Item_func_hex::val_str_ascii_from_val_str().
get_expr_function_type() compared a parsed function name against
function_table[] using strncasecmp() bounded by the length of the parsed
name. The comparison stopped at that length and never checked that the
table entry ended there, so any name that is a prefix of a known
function resolved to that function.
"if" matched "ifnull" and produced a misleading arity error. Names that
prefixed a function with a compatible signature were worse and
dispatched silently: l("AB") ran lcase(),t(" x ") ran trim().
A typo in a test script ran a different function and the test still passed.
Store each entry's length in function_table[] with STRING_WITH_LEN() and
require it to match the parsed length. Report the unmatched name in the
"Unknown function" error.
* restore result=NULL after free in mysqlshow.c (to prevent double-free)
* remove DBUG_EVALUATE_IF again
* remove useless 'stop slave' from a test
* restore charset encoding in mysqltest.{test,result}
* correct error for unparseable BINLOG data is ER_SYNTAX_ERROR now
* restore old libfmt on rhel-7, gcc 4.8.5 cannot compile anything newer
mysqltest substituted variables in the file name of write_file and
append_file, but not in the content, so tests had to fall back to
"exec echo ... >> file" to put a computed value into a file.
Add an optional third parameter, eval, which makes the content go
through do_eval(). It is off by default, because existing tests write
content that contains a literal $ or backslash.
Infer reported MEMORY_LEAK_C at several client sites. Fix the genuine leaks:
client/mysqldump.c (dump_events_for_db): event_list_res (and, on the inner
paths, event_res) were leaked on the error DBUG_RETURN(1) paths
(switch_character_set_results, SHOW CREATE EVENT failure, create_delimiter,
switch_db_collation, restore_db_collation). Route those paths through a
single "err:" cleanup label that frees both results (event_res is kept NULL
outside the inner loop so the shared cleanup is safe) and also restores the
session state (results charset, and UNLOCK TABLES when locking) like the
normal exit does.
client/mysqlshow.c (list_fields): when --keys is given, the columns result
set was overwritten by the "show keys" result without being freed. Free it
before running the keys query, and NULL the pointer so it cannot dangle if
that query fails.
The client/mysqltest.cc reports are false positives (do_save_master_pos only
leaves the result unfreed right before a noreturn die(); read_stmt_results
frees on every path), so no change is needed there.
scripts/fill_help_tables.sql from
https://github.com/mariadb-corporation/mariadb-docs/ as of
3fb208fcdfed06beb52ef9e305017de2387ff012
Other URL changes are taken from the HTTP redirection URL
from the old KB.
Some test cases where impacted:
* ps_missed_cmds{,_bin_prot} - used a topic_id of 0 that is
now used, used MAX_INT instead.
* range_notembedded used the help data as a test case. As its not
a stable table data, replaces with static data. Test case valid
by ensuring the ANALYZE EXPLAIN and optimizer trace had the same
structure. Also valided the MDEV-24739/MDEV-25069 bug fixes from
where the test case originaled, when reverted, exhibited the
previous behavour before the bug fixes.
..passed as argument 2, which is declared to never be null
(dynstr_append_mem).
dynstr_append_mem, uses memcpy to append to the string which in the glibc
library is declared to not take null string as the src. Defensively we
declare dynstr_append_mem to not take a null argument too.
mariadb-test, to prevent it calling dynstr_append_mem with a null
mtr variable value, one that hasn't been initialized, we return an
error if the value is null. The result of this is the $6 in the test
case is never assigned a value and would error.
With this resolved, strchr, if the string isn't found, a null pointer is
returned. UBSAN will complain both about incrementing a pointer beyond
the boundary, and also incrementing if it is null.
Added --galera-info parameter for mysqldump tool and this
will add SET GLOBAL wsrep_start_position line at the
end of the dump. This line is based on added wsrep status
variable wsrep-checkpoint-position.
Added also status variable wsrep-se-checkpoint.
Remove the unscoped #pragma GCC diagnostic ignored
"-Wdeprecated-declarations" from include/violite.h and replace all
sprintf/vsprintf calls with snprintf/vsnprintf across the codebase.
Where possible, pass actual buffer sizes as function parameters
instead of using hardcoded constants or recomputing strlen().
Notable API changes:
- get_date(): added to_len parameter for buffer size
- nice_time(), end_timer() in client/mysql.cc: added buff_size
- generate_new_name(): added name_size parameter
- calc_md5(): added buffer_size parameter (fixes off-by-one)
- MD5_HASH_TO_STRING macro: added _size parameter
- Added MYSQL_UDF_MAX_RESULT_LENGTH constant in mysql_com.h
Also fixed a pre-existing bug in sql/rpl_mi.cc where the ellipsis
"..." was written to the wrong buffer (dbuff instead of buff).
Vendored code is excluded: extra/readline, extra/wolfssl,
wsrep-lib, libmariadb, storage/mroonga/vendor, zlib.
Replace sprintf(buf, ...) with snprintf(buf, sizeof(buf), ...),
where buf is allocated with a size known at compile time.
This makes sure we are not writing outside array/string bounds which will
lead to undefined behaviour. In case the code is trying to write outside bounds
- safe version of functions simply cut the string messages so we process this
gracefully.
When mariadb-dump produces a dump, it first creates a temporary placeholder for views
to satisfy potential dependencies before their actual creation later in the dump file.
Previously, these views were populated with int literals for their columns (1 AS `col_name`).
This could cause syntax or type-resolution errors during restoration if another view depended
on this placeholder view.
This commit changes the placeholder column values from 1 to NULL, as it is more permissive
and allowing the dump to be restored successfully.
When a stored procedure, trigger, or event ends with a line comment (#comment
or --comment), mariadb-dump would append the custom delimiter (;;) on the same line.
This caused the comment to "comment out" the delimiter, leading to syntax errors
during restoration.
Fixed by ensuring a newline is inserted before the delimiter in the dump output.
When multiple mariadb sessions exit at the same time, they all write
to the same $HISTFILE.TMP then rename it to $HISTFILE. The second
rename fails with Errcode 2 because the first already moved the file.
Fix: include the process PID in the temp file name so each session
uses its own unique path and no rename collision can occur.
There was a missing NULL element terminator for --system's type
library definition.
This was causing a crash in find_type_eol when e.g. an incomplete
value was passed to --system where it keeps iterating until it
finds the NULL as a typelib element.
Fixed by appending a NullS to the definition.
Test case added.
mysqltest had limited scripting capabilities, requiring complex
workarounds for mathematical calculations and string manipulations
in test cases. This commit solves these limitations by adding a new
`$(...)` syntax that enables direct evaluation of mathematical, logical,
and string expressions within test scripts.
Expression Evaluation (MDEV-36107):
- Recursive descent parser supporting arithmetic, logical, comparison,
and bitwise operators with proper precedence
- Support for integers (decimal, hex, binary), booleans, strings, and
NULL values
- Variable substitution within expressions
- Integration with existing mysqltest control flow
String Functions (MDEV-36108):
- Base conversion functions supporting bases 2-62
- String manipulation and processing functions
- Regular expression functions
- Conditional and numeric utility functions
The implementation enhances mysqltest's scripting capabilities while
maintaining full backward compatibility.
- refactor batch_readline_init to mysql.cc for proper error handling
- add unit test and move it to the end of main/mysql_client_test.test
to resolve embedded test failures
- remove unnecessary code and duplicates to clean up implementation
- redirect error message from stderr to stdout in .test file
- use labels to avoid code duplication
- handle windows check for block device
- ensure file failing to open in windows because being a directory
is different from any other reason for clear error message
Mariadb monitor when a line is cancelled, provided
its more than one line, passes that text to the
add_history of libedit. This string that has been
passed however isn't null terminated resulting
in an ASAN error within the libedit code.
fix_history where the add_history is called
is called by the com_clear, associated with
the \c command, and com_go. An using the c_ptr
adds a null character onto the end of the string.
- Do not mix latin1 and utf8 in the test and result file.
Not only it looks strange, and it does not work on Windows either.
- Fix --default-character-set usage in mariadb-import.
Prior to patch it was just using platform default when communicating
with server. Now, it uses the charset provided by the option.
- Use --default-character-set=utf8mb4 in test, to have
uniform output across different OSes.
Clang complains that the callback is using a variadic based on an enum.
client/mysql.cc:3207:16: error: passing an object that undergoes default argument promotion to 'va_start' has undefined behavior [-Werror,-Wvarargs]
3207 | va_start(ap, type);
This is part of the C/C API this has been referred as bug:
* CONC-789 MARIADB_OPT_STATUS_CALLBACK Variadic around enums is undefined behaviour
In the mean time, we are just disabling the warning.
Reviewer: Jimmy Hu <jimmy.hu@mariadb.com>
This reverts commit 3e43606de6.
This caused Clang-18+ UBSAN errors:
SUMMARY: UndefinedBehaviorSanitizer: function-type-mismatch libmariadb/libmariadb/mariadb_lib.c:2723:17
+/libmariadb/libmariadb/mariadb_lib.c:2628:3: runtime error: call to function
status_info_cb(void*, enum_mariadb_status_info, enum_session_state_type, st_ma_const_string*)
through pointer to incorrect function type 'void (*)(void *, enum enum_mariadb_status_info, ...)'
+/client/mysql.cc:3204: note: status_info_cb(void*, enum_mariadb_status_info, enum_session_state_type, st_ma_const_string*) defined here
Reviewer: Jimmy Hu <jimmy.hu@mariadb.com>
use my_charset_filename to build file names from table names.
this guarantees that file name will be always valid for any
table name, no matter what characters it contains and what file name
rules local filesystem has.
mariadb-import now converts back, if possible.