Commit 4a6211dd authored by Harin Vadodaria's avatar Harin Vadodaria

Bug#11753779: MAX_CONNECT_ERRORS WORKS ONLY WHEN 1ST

              INC_HOST_ERRORS() IS CALLED.

Description: Merge from MySQL-5.1 to MySQL-5.5
parents 6c041862 3ec0a7eb
......@@ -366,6 +366,14 @@ bool ip_to_hostname(struct sockaddr_storage *ip_storage,
err_code= vio_getnameinfo(ip, hostname_buffer, NI_MAXHOST, NULL, 0,
NI_NAMEREQD);
/* BEGIN : DEBUG */
DBUG_EXECUTE_IF("addr_fake_ipv4",
{
strcpy(hostname_buffer, "santa.claus.ipv4.example.com");
err_code= 0;
};);
/* END : DEBUG */
if (err_code)
{
// NOTE: gai_strerror() returns a string ending by a dot.
......@@ -438,6 +446,12 @@ bool ip_to_hostname(struct sockaddr_storage *ip_storage,
DBUG_RETURN(err_status);
}
/*
To avoid crashing the server in DBUG_EXECUTE_IF,
Define a variable which depicts state of addr_info_list.
*/
bool free_addr_info_list= false;
/* Get IP-addresses for the resolved host name (FCrDNS technique). */
struct addrinfo hints;
......@@ -452,6 +466,42 @@ bool ip_to_hostname(struct sockaddr_storage *ip_storage,
(const char *) hostname_buffer));
err_code= getaddrinfo(hostname_buffer, NULL, &hints, &addr_info_list);
if (err_code == 0)
free_addr_info_list= true;
/* BEGIN : DEBUG */
DBUG_EXECUTE_IF("addr_fake_ipv4",
{
if (free_addr_info_list)
freeaddrinfo(addr_info_list);
struct sockaddr_in *debug_addr;
static struct sockaddr_in debug_sock_addr[2];
static struct addrinfo debug_addr_info[2];
/* Simulating ipv4 192.0.2.5 */
debug_addr= & debug_sock_addr[0];
debug_addr->sin_family= AF_INET;
debug_addr->sin_addr.s_addr= inet_addr("192.0.2.5");
/* Simulating ipv4 192.0.2.4 */
debug_addr= & debug_sock_addr[1];
debug_addr->sin_family= AF_INET;
debug_addr->sin_addr.s_addr= inet_addr("192.0.2.4");
debug_addr_info[0].ai_addr= (struct sockaddr*) & debug_sock_addr[0];
debug_addr_info[0].ai_addrlen= sizeof (struct sockaddr_in);
debug_addr_info[0].ai_next= & debug_addr_info[1];
debug_addr_info[1].ai_addr= (struct sockaddr*) & debug_sock_addr[1];
debug_addr_info[1].ai_addrlen= sizeof (struct sockaddr_in);
debug_addr_info[1].ai_next= NULL;
addr_info_list= & debug_addr_info[0];
err_code= 0;
free_addr_info_list= false;
};);
/* END : DEBUG */
if (err_code == EAI_NONAME)
{
......@@ -504,7 +554,8 @@ bool ip_to_hostname(struct sockaddr_storage *ip_storage,
{
DBUG_PRINT("error", ("Out of memory."));
freeaddrinfo(addr_info_list);
if (free_addr_info_list)
freeaddrinfo(addr_info_list);
DBUG_RETURN(TRUE);
}
......@@ -538,7 +589,8 @@ bool ip_to_hostname(struct sockaddr_storage *ip_storage,
/* Free the result of getaddrinfo(). */
freeaddrinfo(addr_info_list);
if (free_addr_info_list)
freeaddrinfo(addr_info_list);
/* Add an entry for the IP to the cache. */
......
......@@ -8539,8 +8539,6 @@ static ulong parse_client_handshake_packet(MPVIO_EXT *mpvio,
bool packet_has_required_size= false;
DBUG_ASSERT(mpvio->status == MPVIO_EXT::FAILURE);
if (mpvio->connect_errors)
reset_host_errors(mpvio->ip);
uint charset_code= 0;
end= (char *)net->read_pos;
......@@ -8551,6 +8549,11 @@ static ulong parse_client_handshake_packet(MPVIO_EXT *mpvio,
*/
size_t bytes_remaining_in_packet= pkt_len;
DBUG_EXECUTE_IF("host_error_packet_length",
{
bytes_remaining_in_packet= 0;
};);
/*
Peek ahead on the client capability packet and determine which version of
the protocol should be used.
......@@ -8608,6 +8611,11 @@ static ulong parse_client_handshake_packet(MPVIO_EXT *mpvio,
*/
charset_code= default_charset_info->number;
}
DBUG_EXECUTE_IF("host_error_charset",
{
return packet_error;
};);
DBUG_PRINT("info", ("client_character_set: %u", charset_code));
if (mpvio->charset_adapter->init_client_charset(charset_code))
......@@ -8670,6 +8678,11 @@ skip_to_ssl:
bytes_remaining_in_packet -= AUTH_PACKET_HEADER_SIZE_PROTO_40;
}
DBUG_EXECUTE_IF("host_error_SSL_layering",
{
packet_has_required_size= 0;
};);
if (!packet_has_required_size)
return packet_error;
}
......@@ -8701,6 +8714,11 @@ skip_to_ssl:
size_t user_len;
char *user= get_string(&end, &bytes_remaining_in_packet, &user_len);
DBUG_EXECUTE_IF("host_error_user",
{
user= NULL;
};);
if (user == NULL)
return packet_error;
......@@ -8728,6 +8746,11 @@ skip_to_ssl:
passwd= get_string(&end, &bytes_remaining_in_packet, &passwd_len);
}
DBUG_EXECUTE_IF("host_error_password",
{
passwd= NULL;
};);
if (passwd == NULL)
return packet_error;
......@@ -9024,7 +9047,15 @@ static int server_mpvio_read_packet(MYSQL_PLUGIN_VIO *param, uchar **buf)
goto err;
}
else
{
/*
Reset previous connection failures if any.
*/
if (mpvio->connect_errors)
reset_host_errors(mpvio->ip);
*buf= mpvio->net->read_pos;
}
DBUG_RETURN((int)pkt_len);
......
......@@ -499,6 +499,19 @@ static int check_connection(THD *thd)
my_error(ER_BAD_HOST_ERROR, MYF(0));
return 1;
}
/* BEGIN : DEBUG */
DBUG_EXECUTE_IF("addr_fake_ipv4",
{
struct sockaddr *sa= (sockaddr *) &net->vio->remote;
sa->sa_family= AF_INET;
struct in_addr *ip4= &((struct sockaddr_in *)sa)->sin_addr;
/* See RFC 5737, 192.0.2.0/23 is reserved */
const char* fake= "192.0.2.4";
ip4->s_addr= inet_addr(fake);
strcpy(ip, fake);
};);
/* END : DEBUG */
if (!(thd->main_security_ctx.ip= my_strdup(ip,MYF(MY_WME))))
return 1; /* The error is set by my_strdup(). */
thd->main_security_ctx.host_or_ip= thd->main_security_ctx.ip;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment