Skip to content

Commit 9688cbc

Browse files
author
Igor Solodovnikov
committed
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.
1 parent 58b9807 commit 9688cbc

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

sql-common/client.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4230,17 +4230,27 @@ const char * STDCALL mysql_error(MYSQL *mysql)
42304230
42314231
RETURN
42324232
Signed number > 323000
4233+
Zero if there is no connection
42334234
*/
42344235

42354236
ulong STDCALL
42364237
mysql_get_server_version(MYSQL *mysql)
42374238
{
4238-
uint major, minor, version;
4239-
char *pos= mysql->server_version, *end_pos;
4240-
major= (uint) strtoul(pos, &end_pos, 10); pos=end_pos+1;
4241-
minor= (uint) strtoul(pos, &end_pos, 10); pos=end_pos+1;
4242-
version= (uint) strtoul(pos, &end_pos, 10);
4243-
return (ulong) major*10000L+(ulong) (minor*100+version);
4239+
ulong major= 0, minor= 0, version= 0;
4240+
4241+
if (mysql->server_version)
4242+
{
4243+
char *pos= mysql->server_version, *end_pos;
4244+
major= strtoul(pos, &end_pos, 10); pos=end_pos+1;
4245+
minor= strtoul(pos, &end_pos, 10); pos=end_pos+1;
4246+
version= strtoul(pos, &end_pos, 10);
4247+
}
4248+
else
4249+
{
4250+
set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);
4251+
}
4252+
4253+
return major*10000 + minor*100 + version;
42444254
}
42454255

42464256

0 commit comments

Comments
 (0)