Merge mysql-5.5 to working copy.

This commit is contained in:
Marko Mäkelä 2012-09-17 15:08:34 +03:00
commit 2f648ec6be
3 changed files with 98 additions and 4 deletions

View File

@ -366,6 +366,14 @@ bool ip_to_hostname(struct sockaddr_storage *ip_storage,
err_code= vio_getnameinfo(ip, hostname_buffer, NI_MAXHOST, NULL, 0, err_code= vio_getnameinfo(ip, hostname_buffer, NI_MAXHOST, NULL, 0,
NI_NAMEREQD); 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) if (err_code)
{ {
// NOTE: gai_strerror() returns a string ending by a dot. // 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); 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). */ /* Get IP-addresses for the resolved host name (FCrDNS technique). */
struct addrinfo hints; struct addrinfo hints;
@ -452,6 +466,42 @@ bool ip_to_hostname(struct sockaddr_storage *ip_storage,
(const char *) hostname_buffer)); (const char *) hostname_buffer));
err_code= getaddrinfo(hostname_buffer, NULL, &hints, &addr_info_list); 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) if (err_code == EAI_NONAME)
{ {
@ -504,6 +554,7 @@ bool ip_to_hostname(struct sockaddr_storage *ip_storage,
{ {
DBUG_PRINT("error", ("Out of memory.")); DBUG_PRINT("error", ("Out of memory."));
if (free_addr_info_list)
freeaddrinfo(addr_info_list); freeaddrinfo(addr_info_list);
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
} }
@ -538,6 +589,7 @@ bool ip_to_hostname(struct sockaddr_storage *ip_storage,
/* Free the result of getaddrinfo(). */ /* Free the result of getaddrinfo(). */
if (free_addr_info_list)
freeaddrinfo(addr_info_list); freeaddrinfo(addr_info_list);
/* Add an entry for the IP to the cache. */ /* Add an entry for the IP to the cache. */

View File

@ -8540,8 +8540,6 @@ static ulong parse_client_handshake_packet(MPVIO_EXT *mpvio,
bool packet_has_required_size= false; bool packet_has_required_size= false;
DBUG_ASSERT(mpvio->status == MPVIO_EXT::FAILURE); DBUG_ASSERT(mpvio->status == MPVIO_EXT::FAILURE);
if (mpvio->connect_errors)
reset_host_errors(mpvio->ip);
uint charset_code= 0; uint charset_code= 0;
end= (char *)net->read_pos; 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; 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 Peek ahead on the client capability packet and determine which version of
the protocol should be used. the protocol should be used.
@ -8609,6 +8612,11 @@ static ulong parse_client_handshake_packet(MPVIO_EXT *mpvio,
*/ */
charset_code= default_charset_info->number; charset_code= default_charset_info->number;
} }
DBUG_EXECUTE_IF("host_error_charset",
{
return packet_error;
};);
DBUG_PRINT("info", ("client_character_set: %u", charset_code)); DBUG_PRINT("info", ("client_character_set: %u", charset_code));
if (mpvio->charset_adapter->init_client_charset(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; 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) if (!packet_has_required_size)
return packet_error; return packet_error;
} }
@ -8702,6 +8715,11 @@ skip_to_ssl:
size_t user_len; size_t user_len;
char *user= get_string(&end, &bytes_remaining_in_packet, &user_len); char *user= get_string(&end, &bytes_remaining_in_packet, &user_len);
DBUG_EXECUTE_IF("host_error_user",
{
user= NULL;
};);
if (user == NULL) if (user == NULL)
return packet_error; return packet_error;
@ -8729,6 +8747,11 @@ skip_to_ssl:
passwd= get_string(&end, &bytes_remaining_in_packet, &passwd_len); passwd= get_string(&end, &bytes_remaining_in_packet, &passwd_len);
} }
DBUG_EXECUTE_IF("host_error_password",
{
passwd= NULL;
};);
if (passwd == NULL) if (passwd == NULL)
return packet_error; 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; thd->net.skip_big_packet= TRUE;
#endif #endif
/*
Reset previous connection failures if any.
*/
if (mpvio.connect_errors)
reset_host_errors(mpvio.ip);
/* Ready to handle queries */ /* Ready to handle queries */
DBUG_RETURN(0); DBUG_RETURN(0);
} }

View File

@ -499,6 +499,19 @@ static int check_connection(THD *thd)
my_error(ER_BAD_HOST_ERROR, MYF(0)); my_error(ER_BAD_HOST_ERROR, MYF(0));
return 1; 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)))) if (!(thd->main_security_ctx.ip= my_strdup(ip,MYF(MY_WME))))
return 1; /* The error is set by my_strdup(). */ return 1; /* The error is set by my_strdup(). */
thd->main_security_ctx.host_or_ip= thd->main_security_ctx.ip; thd->main_security_ctx.host_or_ip= thd->main_security_ctx.ip;