summaryrefslogtreecommitdiff
path: root/sql-common
diff options
context:
space:
mode:
Diffstat (limited to 'sql-common')
-rw-r--r--sql-common/client.c96
-rw-r--r--sql-common/my_time.c8
2 files changed, 57 insertions, 47 deletions
diff --git a/sql-common/client.c b/sql-common/client.c
index 45cd8befdf0..6722597531d 100644
--- a/sql-common/client.c
+++ b/sql-common/client.c
@@ -71,11 +71,6 @@ my_bool net_flush(NET *net);
#include <my_pthread.h> /* because of signal() */
#endif /* defined(THREAD) && !defined(__WIN__) */
-#if defined(OS2) && defined(MYSQL_SERVER)
-#undef ER
-#define ER CER
-#endif /* defined( OS2) && defined(MYSQL_SERVER) */
-
#include <sys/stat.h>
#include <signal.h>
#include <time.h>
@@ -126,7 +121,7 @@ const char *def_shared_memory_base_name= default_shared_memory_base_name;
static void mysql_close_free_options(MYSQL *mysql);
static void mysql_close_free(MYSQL *mysql);
-#if !(defined(__WIN__) || defined(OS2) || defined(__NETWARE__))
+#if !(defined(__WIN__) || defined(__NETWARE__))
static int wait_for_data(my_socket fd, uint timeout);
#endif
@@ -145,7 +140,7 @@ CHARSET_INFO *default_client_charset_info = &my_charset_latin1;
int my_connect(my_socket fd, const struct sockaddr *name, uint namelen,
uint timeout)
{
-#if defined(__WIN__) || defined(OS2) || defined(__NETWARE__)
+#if defined(__WIN__) || defined(__NETWARE__)
return connect(fd, (struct sockaddr*) name, namelen);
#else
int flags, res, s_err;
@@ -185,7 +180,7 @@ int my_connect(my_socket fd, const struct sockaddr *name, uint namelen,
If not, we will use select()
*/
-#if !(defined(__WIN__) || defined(OS2) || defined(__NETWARE__))
+#if !(defined(__WIN__) || defined(__NETWARE__))
static int wait_for_data(my_socket fd, uint timeout)
{
@@ -276,7 +271,7 @@ static int wait_for_data(my_socket fd, uint timeout)
return (0); /* ok */
#endif /* HAVE_POLL */
}
-#endif /* defined(__WIN__) || defined(OS2) || defined(__NETWARE__) */
+#endif /* defined(__WIN__) || defined(__NETWARE__) */
/*
@@ -584,7 +579,7 @@ err:
*****************************************************************************/
ulong
-net_safe_read(MYSQL *mysql)
+cli_safe_read(MYSQL *mysql)
{
NET *net= &mysql->net;
ulong len=0;
@@ -627,6 +622,16 @@ net_safe_read(MYSQL *mysql)
}
else
set_mysql_error(mysql, CR_UNKNOWN_ERROR, unknown_sqlstate);
+ /*
+ Cover a protocol design error: error packet does not
+ contain the server status. Therefore, the client has no way
+ to find out whether there are more result sets of
+ a multiple-result-set statement pending. Luckily, in 5.0 an
+ error always aborts execution of a statement, wherever it is
+ a multi-statement or a stored procedure, so it should be
+ safe to unconditionally turn off the flag here.
+ */
+ mysql->server_status&= ~SERVER_MORE_RESULTS_EXISTS;
DBUG_PRINT("error",("Got error: %d/%s (%s)",
net->last_errno, net->sqlstate, net->last_error));
@@ -653,7 +658,7 @@ cli_advanced_command(MYSQL *mysql, enum enum_server_command command,
NET *net= &mysql->net;
my_bool result= 1;
init_sigpipe_variables
- DBUG_ENTER("cli_advanced_command");
+ DBUG_ENTER("cli_advanced_command");
/* Don't give sigpipe errors if the client doesn't want them */
set_sigpipe(mysql);
@@ -663,7 +668,8 @@ cli_advanced_command(MYSQL *mysql, enum enum_server_command command,
if (mysql_reconnect(mysql))
DBUG_RETURN(1);
}
- if (mysql->status != MYSQL_STATUS_READY)
+ if (mysql->status != MYSQL_STATUS_READY ||
+ mysql->server_status & SERVER_MORE_RESULTS_EXISTS)
{
DBUG_PRINT("error",("state: %d", mysql->status));
set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);
@@ -702,7 +708,7 @@ cli_advanced_command(MYSQL *mysql, enum enum_server_command command,
}
result=0;
if (!skip_check)
- result= ((mysql->packet_length=net_safe_read(mysql)) == packet_error ?
+ result= ((mysql->packet_length=cli_safe_read(mysql)) == packet_error ?
1 : 0);
end:
reset_sigpipe(mysql);
@@ -754,7 +760,7 @@ static void cli_flush_use_result(MYSQL *mysql)
for (;;)
{
ulong pkt_len;
- if ((pkt_len=net_safe_read(mysql)) == packet_error)
+ if ((pkt_len=cli_safe_read(mysql)) == packet_error)
break;
if (pkt_len <= 8 && mysql->net.read_pos[0] == 254)
{
@@ -1276,7 +1282,7 @@ MYSQL_DATA *cli_read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields,
NET *net = &mysql->net;
DBUG_ENTER("cli_read_rows");
- if ((pkt_len= net_safe_read(mysql)) == packet_error)
+ if ((pkt_len= cli_safe_read(mysql)) == packet_error)
DBUG_RETURN(0);
if (!(result=(MYSQL_DATA*) my_malloc(sizeof(MYSQL_DATA),
MYF(MY_WME | MY_ZEROFILL))))
@@ -1341,7 +1347,7 @@ MYSQL_DATA *cli_read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields,
}
}
cur->data[field]=to; /* End of last field */
- if ((pkt_len=net_safe_read(mysql)) == packet_error)
+ if ((pkt_len=cli_safe_read(mysql)) == packet_error)
{
free_rows(result);
DBUG_RETURN(0);
@@ -1373,7 +1379,7 @@ read_one_row(MYSQL *mysql,uint fields,MYSQL_ROW row, ulong *lengths)
uchar *pos, *prev_pos, *end_pos;
NET *net= &mysql->net;
- if ((pkt_len=net_safe_read(mysql)) == packet_error)
+ if ((pkt_len=cli_safe_read(mysql)) == packet_error)
return -1;
if (pkt_len <= 8 && net->read_pos[0] == 254)
{
@@ -1503,7 +1509,6 @@ mysql_ssl_set(MYSQL *mysql __attribute__((unused)) ,
mysql->options.ssl_ca= strdup_if_not_null(ca);
mysql->options.ssl_capath= strdup_if_not_null(capath);
mysql->options.ssl_cipher= strdup_if_not_null(cipher);
- mysql->options.ssl_verify_server_cert= FALSE; /* Off by default */
#endif /* HAVE_OPENSSL */
DBUG_RETURN(0);
}
@@ -1650,23 +1655,23 @@ static MYSQL_RES *cli_use_result(MYSQL *mysql);
static MYSQL_METHODS client_methods=
{
- cli_read_query_result,
- cli_advanced_command,
- cli_read_rows,
- cli_use_result,
- cli_fetch_lengths,
- cli_flush_use_result
+ cli_read_query_result, /* read_query_result */
+ cli_advanced_command, /* advanced_command */
+ cli_read_rows, /* read_rows */
+ cli_use_result, /* use_result */
+ cli_fetch_lengths, /* fetch_lengths */
+ cli_flush_use_result /* flush_use_result */
#ifndef MYSQL_SERVER
- ,cli_list_fields,
- cli_read_prepare_result,
- cli_stmt_execute,
- cli_read_binary_rows,
- cli_unbuffered_fetch,
- NULL,
- cli_read_statistics,
- cli_read_query_result,
- cli_read_change_user_result,
- cli_read_binary_rows
+ ,cli_list_fields, /* list_fields */
+ cli_read_prepare_result, /* read_prepare_result */
+ cli_stmt_execute, /* stmt_execute */
+ cli_read_binary_rows, /* read_binary_rows */
+ cli_unbuffered_fetch, /* unbuffered_fetch */
+ NULL, /* free_embedded_thd */
+ cli_read_statistics, /* read_statistics */
+ cli_read_query_result, /* next_result */
+ cli_read_change_user_result, /* read_change_user_result */
+ cli_read_binary_rows /* read_rows_from_cursor */
#endif
};
@@ -1748,7 +1753,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
const char *passwd, const char *db,
uint port, const char *unix_socket,ulong client_flag)
{
- char buff[NAME_LEN+USERNAME_LENGTH+100];
+ char buff[NAME_BYTE_LEN+USERNAME_BYTE_LENGTH+100];
char *end,*host_info;
my_socket sock;
in_addr_t ip_addr;
@@ -2029,7 +2034,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
Part 1: Connection established, read and parse first packet
*/
- if ((pkt_length=net_safe_read(mysql)) == packet_error)
+ if ((pkt_length=cli_safe_read(mysql)) == packet_error)
goto error;
/* Check if version of protocol matches current one */
@@ -2192,7 +2197,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
DBUG_PRINT("info", ("IO layer change done!"));
/* Verify server cert */
- if (mysql->options.ssl_verify_server_cert &&
+ if ((client_flag & CLIENT_SSL_VERIFY_SERVER_CERT) &&
ssl_verify_server_cert(mysql->net.vio, mysql->host))
{
set_mysql_error(mysql, CR_SSL_CONNECTION_ERROR, unknown_sqlstate);
@@ -2207,7 +2212,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
mysql->server_status, client_flag));
/* This needs to be changed as it's not useful with big packets */
if (user && user[0])
- strmake(end,user,USERNAME_LENGTH); /* Max user name */
+ strmake(end,user,USERNAME_BYTE_LENGTH); /* Max user name */
else
read_user_name((char*) end);
@@ -2237,7 +2242,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
/* Add database if needed */
if (db && (mysql->server_capabilities & CLIENT_CONNECT_WITH_DB))
{
- end= strmake(end, db, NAME_LEN) + 1;
+ end= strmake(end, db, NAME_BYTE_LEN) + 1;
mysql->db= my_strdup(db,MYF(MY_WME));
db= 0;
}
@@ -2253,7 +2258,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
OK-packet, or re-request scrambled password.
*/
- if ((pkt_length=net_safe_read(mysql)) == packet_error)
+ if ((pkt_length=cli_safe_read(mysql)) == packet_error)
goto error;
if (pkt_length == 1 && net->read_pos[0] == 254 &&
@@ -2270,7 +2275,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
goto error;
}
/* Read what server thinks about out new auth message report */
- if (net_safe_read(mysql) == packet_error)
+ if (cli_safe_read(mysql) == packet_error)
goto error;
}
@@ -2594,7 +2599,7 @@ static my_bool cli_read_query_result(MYSQL *mysql)
*/
mysql = mysql->last_used_con;
- if ((length = net_safe_read(mysql)) == packet_error)
+ if ((length = cli_safe_read(mysql)) == packet_error)
DBUG_RETURN(1);
free_old_query(mysql); /* Free old result */
#ifdef MYSQL_CLIENT /* Avoid warn of unused labels*/
@@ -2629,7 +2634,7 @@ get_info:
if (field_count == NULL_LENGTH) /* LOAD DATA LOCAL INFILE */
{
int error=handle_local_infile(mysql,(char*) pos);
- if ((length=net_safe_read(mysql)) == packet_error || error)
+ if ((length= cli_safe_read(mysql)) == packet_error || error)
DBUG_RETURN(1);
goto get_info; /* Get info packet */
}
@@ -2939,7 +2944,10 @@ mysql_options(MYSQL *mysql,enum mysql_option option, const char *arg)
mysql->reconnect= *(my_bool *) arg;
break;
case MYSQL_OPT_SSL_VERIFY_SERVER_CERT:
- mysql->options.ssl_verify_server_cert= *(my_bool *) arg;
+ if (!arg || test(*(uint*) arg))
+ mysql->options.client_flag|= CLIENT_SSL_VERIFY_SERVER_CERT;
+ else
+ mysql->options.client_flag&= ~CLIENT_SSL_VERIFY_SERVER_CERT;
break;
default:
DBUG_RETURN(1);
diff --git a/sql-common/my_time.c b/sql-common/my_time.c
index d90c4ef0fde..29de0504468 100644
--- a/sql-common/my_time.c
+++ b/sql-common/my_time.c
@@ -69,6 +69,7 @@ uint calc_days_in_year(uint year)
Here we assume that year and month is ok !
If month is 0 we allow any date. (This only happens if we allow zero
date parts in str_to_datetime())
+ Disallow dates with zero year and non-zero month and/or day.
RETURN
0 ok
@@ -85,7 +86,8 @@ static my_bool check_date(const MYSQL_TIME *ltime, my_bool not_zero_date,
(!(flags & TIME_INVALID_DATES) &&
ltime->month && ltime->day > days_in_month[ltime->month-1] &&
(ltime->month != 2 || calc_days_in_year(ltime->year) != 366 ||
- ltime->day != 29)))
+ ltime->day != 29)) ||
+ (ltime->year == 0 && (ltime->month != 0 || ltime->day != 0)))
{
*was_cut= 2;
return TRUE;
@@ -427,7 +429,7 @@ str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time,
goto err;
}
- if (check_date(l_time, not_zero_date, flags, was_cut))
+ if ((my_bool)check_date(l_time, not_zero_date, flags, was_cut))
goto err;
l_time->time_type= (number_of_fields <= 3 ?
@@ -737,7 +739,7 @@ long calc_daynr(uint year,uint month,uint day)
if (year == 0 && month == 0 && day == 0)
DBUG_RETURN(0); /* Skip errors */
- if (year < 200)
+ if (year < YY_MAGIC_BELOW)
{
if ((year=year+1900) < 1900+YY_PART_YEAR)
year+=100;