mirror of
https://github.com/MariaDB/server.git
synced 2025-03-25 00:18:42 +01:00
Bug#11753779: MAX_CONNECT_ERRORS WORKS ONLY WHEN 1ST
INC_HOST_ERRORS() IS CALLED. Description : Merge from MySQL-5.1 to MySQL-5.5
This commit is contained in:
commit
61f88b697f
3 changed files with 98 additions and 4 deletions
|
@ -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. */
|
||||
|
||||
|
|
|
@ -8540,8 +8540,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;
|
||||
|
@ -8552,6 +8550,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.
|
||||
|
@ -8609,6 +8612,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))
|
||||
|
@ -8671,6 +8679,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;
|
||||
}
|
||||
|
@ -8702,6 +8715,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;
|
||||
|
||||
|
@ -8729,6 +8747,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;
|
||||
|
||||
|
@ -9527,6 +9550,12 @@ acl_authenticate(THD *thd, uint connect_errors, uint com_change_user_pkt_len)
|
|||
thd->net.skip_big_packet= TRUE;
|
||||
#endif
|
||||
|
||||
/*
|
||||
Reset previous connection failures if any.
|
||||
*/
|
||||
if (mpvio.connect_errors)
|
||||
reset_host_errors(mpvio.ip);
|
||||
|
||||
/* Ready to handle queries */
|
||||
DBUG_RETURN(0);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue