diff options
author | Igor Solodovnikov <igor.solodovnikov@oracle.com> | 2014-04-17 16:33:55 +0300 |
---|---|---|
committer | Igor Solodovnikov <igor.solodovnikov@oracle.com> | 2014-04-17 16:33:55 +0300 |
commit | 22e9aa1c1a9607e56620be93728479331ab90ed5 (patch) | |
tree | 9defaf3fb975020ab31a2f48ab0c870617073424 /sql-common | |
parent | 1b74f2e3da53dd8b965920fad2ff599df2d1fc89 (diff) | |
download | mariadb-git-22e9aa1c1a9607e56620be93728479331ab90ed5.tar.gz |
Bug #18053212 MYSQL_GET_SERVER_VERSION() CALL WITHOUT A VALID CONNECTION RESULTS IN SEG FAULT
When there is no connection mysql_get_server_version() will return 0
and report CR_COMMANDS_OUT_OF_SYNC error.
Diffstat (limited to 'sql-common')
-rw-r--r-- | sql-common/client.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/sql-common/client.c b/sql-common/client.c index 16a61d7f53d..f2c091261b4 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -4230,17 +4230,27 @@ const char * STDCALL mysql_error(MYSQL *mysql) RETURN Signed number > 323000 + Zero if there is no connection */ ulong STDCALL mysql_get_server_version(MYSQL *mysql) { - uint major, minor, version; - char *pos= mysql->server_version, *end_pos; - major= (uint) strtoul(pos, &end_pos, 10); pos=end_pos+1; - minor= (uint) strtoul(pos, &end_pos, 10); pos=end_pos+1; - version= (uint) strtoul(pos, &end_pos, 10); - return (ulong) major*10000L+(ulong) (minor*100+version); + ulong major= 0, minor= 0, version= 0; + + if (mysql->server_version) + { + char *pos= mysql->server_version, *end_pos; + major= strtoul(pos, &end_pos, 10); pos=end_pos+1; + minor= strtoul(pos, &end_pos, 10); pos=end_pos+1; + version= strtoul(pos, &end_pos, 10); + } + else + { + set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate); + } + + return major*10000 + minor*100 + version; } |