Skip to content

Commit 6d86d29

Browse files
author
Anushree Prakash B
committed
Bug#25510805 - MYSQL CRASHES WHEN TRYING TO CONNECT FROM
A HOST WITH AHOSTNAME OF 69 CHARACTERS DESCRIPTION: =========== When a connection is made from a host with a hostname length of more than HOSTNAME_LENGTH characters, MySQL crashes with a buffer overflow. ANALYSIS: ======== If the hostname of the connecting host is greater than HOSTNAME_LENGTH (60 chars), copying the hostname to the performance schema table field which is limited to HOSTNAME_LENGTH characters results in a crash. FIX: === The fix is to truncate the hostname to HOSTNAME_LENGTH number of characters before adding them to the performance schema tables which record host information and details. This makes sure that the client connection is established successfully.
1 parent 97c4cd5 commit 6d86d29

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

sql/hostname.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
// sql_print_information
3434
#include "violite.h" // vio_getnameinfo,
3535
// vio_get_normalized_ip_string
36+
#include <string>
3637
#ifdef __cplusplus
3738
extern "C" { // Because of SCO 3.2V4.2
3839
#endif
@@ -551,6 +552,14 @@ int ip_to_hostname(struct sockaddr_storage *ip_storage,
551552
}
552553
);
553554

555+
DBUG_EXECUTE_IF ("getnameinfo_fake_max_length",
556+
{
557+
std::string s(NI_MAXHOST-1, 'a');
558+
strcpy(hostname_buffer, s.c_str());
559+
err_code= 0;
560+
}
561+
);
562+
554563
/*
555564
===========================================================================
556565
DEBUG code only (end)

storage/perfschema/pfs.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "sp_head.h"
4242
#include "pfs_digest.h"
4343

44+
using std::min;
4445
/**
4546
@page PAGE_PERFORMANCE_SCHEMA The Performance Schema main page
4647
MySQL PERFORMANCE_SCHEMA implementation.
@@ -2018,7 +2019,8 @@ static void set_thread_account_v1(const char *user, int user_len,
20182019
DBUG_ASSERT((uint) user_len <= sizeof(pfs->m_username));
20192020
DBUG_ASSERT((host != NULL) || (host_len == 0));
20202021
DBUG_ASSERT(host_len >= 0);
2021-
DBUG_ASSERT((uint) host_len <= sizeof(pfs->m_hostname));
2022+
2023+
host_len= min<size_t>(host_len, sizeof(pfs->m_hostname));
20222024

20232025
if (unlikely(pfs == NULL))
20242026
return;

0 commit comments

Comments
 (0)