Skip to content

Commit

Permalink
MDEV-33045: Server crashes in Item_func_binlog_gtid_pos::val_str / Bi…
Browse files Browse the repository at this point in the history
…nary_string::c_ptr_safe

Item::val_str() sets the Item::null_value flag, so call it before checking
the flag, not after.

Signed-off-by: Kristian Nielsen <knielsen@knielsen-hq.org>
  • Loading branch information
knielsen committed Dec 19, 2023
1 parent be69438 commit a204ce2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
7 changes: 7 additions & 0 deletions mysql-test/suite/binlog_encryption/rpl_gtid_basic.result
Expand Up @@ -182,6 +182,13 @@ BINLOG_GTID_POS('master-bin.000001',18446744073709551616)
NULL
Warnings:
Warning 1916 Got overflow when converting '18446744073709551616' to INT. Value truncated
SET sql_log_bin= 0;
CREATE TABLE t1 AS SELECT MASTER_POS_WAIT(@binlog_file, 4, 0);
SELECT BINLOG_GTID_POS(@binlog_file, 4);
BINLOG_GTID_POS(@binlog_file, 4)
NULL
DROP TABLE t1;
SET sql_log_bin= 1;
*** Some tests of @@GLOBAL.gtid_binlog_state ***
connection server_2;
include/sync_with_master_gtid.inc
Expand Down
7 changes: 7 additions & 0 deletions mysql-test/suite/rpl/r/rpl_gtid_basic.result
Expand Up @@ -182,6 +182,13 @@ BINLOG_GTID_POS('master-bin.000001',18446744073709551616)
NULL
Warnings:
Warning 1916 Got overflow when converting '18446744073709551616' to INT. Value truncated
SET sql_log_bin= 0;
CREATE TABLE t1 AS SELECT MASTER_POS_WAIT(@binlog_file, 4, 0);
SELECT BINLOG_GTID_POS(@binlog_file, 4);
BINLOG_GTID_POS(@binlog_file, 4)
NULL
DROP TABLE t1;
SET sql_log_bin= 1;
*** Some tests of @@GLOBAL.gtid_binlog_state ***
connection server_2;
include/sync_with_master_gtid.inc
Expand Down
7 changes: 7 additions & 0 deletions mysql-test/suite/rpl/t/rpl_gtid_basic.test
Expand Up @@ -162,6 +162,13 @@ eval SELECT BINLOG_GTID_POS('$valid_binlog_name',0);
eval SELECT BINLOG_GTID_POS('$valid_binlog_name',18446744073709551615);
eval SELECT BINLOG_GTID_POS('$valid_binlog_name',18446744073709551616);

# MDEV-33045: Server crashes in Item_func_binlog_gtid_pos::val_str / Binary_string::c_ptr_safe
SET sql_log_bin= 0;
CREATE TABLE t1 AS SELECT MASTER_POS_WAIT(@binlog_file, 4, 0);
SELECT BINLOG_GTID_POS(@binlog_file, 4);
DROP TABLE t1;
SET sql_log_bin= 1;


--echo *** Some tests of @@GLOBAL.gtid_binlog_state ***
--connection server_2
Expand Down
6 changes: 3 additions & 3 deletions sql/item_strfunc.cc
Expand Up @@ -3232,12 +3232,12 @@ String *Item_func_binlog_gtid_pos::val_str(String *str)
String name_str, *name;
longlong pos;

if (args[0]->null_value || args[1]->null_value)
goto err;

name= args[0]->val_str(&name_str);
pos= args[1]->val_int();

if (args[0]->null_value || args[1]->null_value)
goto err;

if (pos < 0 || pos > UINT_MAX32)
goto err;

Expand Down

0 comments on commit a204ce2

Please sign in to comment.