diff --git a/lib/MySQL_Thread.cpp b/lib/MySQL_Thread.cpp index d8943ef32..cb9f4f4c8 100644 --- a/lib/MySQL_Thread.cpp +++ b/lib/MySQL_Thread.cpp @@ -2430,6 +2430,13 @@ std::string get_client_addr(struct sockaddr* client_addr) { MySQL_Client_Host_Cache_Entry MySQL_Threads_Handler::find_client_host_cache(struct sockaddr* client_sockaddr) { MySQL_Client_Host_Cache_Entry entry { 0, 0 }; + if (client_sockaddr == NULL) { + // NOTE: client_sockaddr **shouldn't** ever by 'NULL', no matter the + // 'session_type' in from which this function is called. Because + // `MySQL_Session::client_myds::client_addr` should **always** be + // initialized before `handler` is called. + assert(0); + } if (client_sockaddr->sa_family != AF_INET && client_sockaddr->sa_family != AF_INET6) { return entry; } @@ -2520,6 +2527,13 @@ SQLite3_result* MySQL_Threads_Handler::get_client_host_cache(bool reset) { } void MySQL_Threads_Handler::update_client_host_cache(struct sockaddr* client_sockaddr, bool error) { + if (client_sockaddr == NULL) { + // NOTE: client_sockaddr **shouldn't** ever by 'NULL', no matter the + // 'session_type' in from which this function is called. Because + // `MySQL_Session::client_myds::client_addr` should **always** be + // initialized before `handler` is called. + assert(0); + } if (client_sockaddr->sa_family != AF_INET && client_sockaddr->sa_family != AF_INET6) { return; } diff --git a/src/SQLite3_Server.cpp b/src/SQLite3_Server.cpp index 5ebfe4a17..d14d71afe 100644 --- a/src/SQLite3_Server.cpp +++ b/src/SQLite3_Server.cpp @@ -816,6 +816,22 @@ static void *child_mysql(void *arg) { if (myds->net_failure) goto __exit_child_mysql; myds->read_pkts(); sess->to_process=1; + + // Get and set the client address before the sesion is processed. + union { + struct sockaddr_in in; + struct sockaddr_in6 in6; + } custom_sockaddr; + struct sockaddr *addr=(struct sockaddr *)malloc(sizeof(custom_sockaddr)); + socklen_t addrlen=sizeof(custom_sockaddr); + memset(addr, 0, sizeof(custom_sockaddr)); + sess->client_myds->client_addrlen=addrlen; + sess->client_myds->client_addr=addr; + int g_rc = getpeername(sess->client_myds->fd, addr, &addrlen); + if (g_rc == -1) { + proxy_error("'getpeername' failed with error: %d\n", rc); + } + int rc=sess->handler(); if (rc==-1) goto __exit_child_mysql; }