author:sufei
說(shuō)明:本文記錄在最新版本MySQL 8.0.26中存在的一個(gè)bug
現(xiàn)象
使用mysqlsh以u(píng)ri方式創(chuàng)建連接時(shí)耗绿,若uri中的host域名如果中包含user苹支,且user以URL編碼(ASCII形式),同時(shí)password信息也在uri中時(shí)误阻,mysqlsh報(bào)錯(cuò)basic_string::_M_replace_aux
根據(jù)官方文檔债蜜,uri格式如下晴埂,特殊字符可用形如%XX的方式替換
[scheme://][user[:password]@]<host[:port]|socket>[/schema][?option=value&option=value...]
分析
通過(guò)gdb調(diào)試可知亭珍,出錯(cuò)的原因主要是因?yàn)樵趍ysqlsh::hide_password_in_uri中調(diào)用string.replace時(shí)異常
hide_password_in_uri函數(shù)主要是安全考慮鸣剪,隱藏系統(tǒng)進(jìn)程顯示中的密碼信息塔插,如
static std::string hide_password_in_uri(std::string uri,
const std::string &username) {
std::size_t pwd_start = uri.find(username) + username.length() + 1;
std::size_t pwd_size = uri.find('@', pwd_start) - pwd_start;
return uri.replace(pwd_start, pwd_size, pwd_size, '*');
}
// 調(diào)用棧
(gdb) bt
#0 mysqlsh::hide_password_in_uri (uri=..., username=...) at /data2/sf/mysql8/teledb-mysql/8.0.18/mysql-shell-8.0.19-src/mysqlshdk/shellcore/shell_options.cc:108
#1 0x0000000001691634 in mysqlsh::Shell_options::custom_cmdline_handler (this=0x2a20120, iterator=0x7fffffff9690)
at /data2/sf/mysql8/teledb-mysql/8.0.18/mysql-shell-8.0.19-src/mysqlshdk/shellcore/shell_options.cc:714
...
gdb信息
(gdb) show args
Argument list to give program being debugged when it is started is "--uri %72%6f%6f%74:123456@root123:3306".
(gdb) p username.c_str()
$14 = 0x2a1bf90 "root"
(gdb) p pwd_start
$15 = 25
# string.find找不到對(duì)應(yīng)的字符串肤频,返回2^64-1 (25+18446744073709551590)
(gdb) p pwd_size
$16 = 18446744073709551590
# string.replace接收類(lèi)型為size_t羊壹,最大值2^63-1娘扩,導(dǎo)致異常
ps: uri用戶(hù)信息處理函數(shù)
mysqlshdk::db::uri::Uri_parser::parse_userinfo()
# 調(diào)用棧
#0 mysqlshdk::db::uri::Uri_parser::parse_userinfo (this=0x7fffffff88e0) at /data2/sf/mysql8/teledb-mysql/8.0.18/mysql-shell-8.0.19-src/mysqlshdk/libs/db/uri_parser.cc:152
#1 0x000000000154d99f in mysqlshdk::db::uri::Uri_parser::parse (this=0x7fffffff88e0, input=..., mode=mysqlshdk::utils::nullable_options::CASE_INSENSITIVE)
at /data2/sf/mysql8/teledb-mysql/8.0.18/mysql-shell-8.0.19-src/mysqlshdk/libs/db/uri_parser.cc:845
#2 0x00000000014e28f7 in mysqlshdk::db::Connection_options::Connection_options (this=0x7fffffff8f90, uri=..., mode=mysqlshdk::utils::nullable_options::CASE_INSENSITIVE)
at /data2/sf/mysql8/teledb-mysql/8.0.18/mysql-shell-8.0.19-src/mysqlshdk/libs/db/connection_options.cc:79
#3 0x000000000149f9e9 in shcore::get_connection_options (uri=..., set_defaults=false)
at /data2/sf/mysql8/teledb-mysql/8.0.18/mysql-shell-8.0.19-src/mysqlshdk/libs/utils/utils_general.cc:169
#4 0x0000000001691575 in mysqlsh::Shell_options::custom_cmdline_handler (this=0x2a20120, iterator=0x7fffffff9690)
at /data2/sf/mysql8/teledb-mysql/8.0.18/mysql-shell-8.0.19-src/mysqlshdk/shellcore/shell_options.cc:710
官方確認(rèn)
目前組內(nèi)成員已向官方提交相關(guān)bug帮掉,并予以確認(rèn)
官方已確認(rèn)(Bug #104714)