From: Tomek Mrugalski Date: Tue, 20 Oct 2015 16:53:10 +0000 (+0200) Subject: [3682] Couple segfault fixes in passing parameters to MySQL X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6f2fe8b65a93f46d35e25003b8c50fe1e73ad907;p=thirdparty%2Fkea.git [3682] Couple segfault fixes in passing parameters to MySQL --- diff --git a/src/lib/dhcpsrv/mysql_host_data_source.cc b/src/lib/dhcpsrv/mysql_host_data_source.cc index 864cf9e513..e34a316f97 100644 --- a/src/lib/dhcpsrv/mysql_host_data_source.cc +++ b/src/lib/dhcpsrv/mysql_host_data_source.cc @@ -249,29 +249,37 @@ public: // dhcp_identifier_type : TINYINT NOT NULL // Check which of the identifier types is used and set values accordingly if (host_->getHWAddress()) { + dhcp_identifier_type_ = 0; // 0 = IDENT_HWADDR bind_[2].buffer_type = MYSQL_TYPE_TINY; - bind_[2].buffer = reinterpret_cast(0);// 0 = IDENT_HWADDR + bind_[2].buffer = reinterpret_cast(&dhcp_identifier_type_); bind_[2].is_unsigned = MLM_TRUE; // bind_[2].is_null = &MLM_FALSE; // commented out for performance // reasons, see memset() above } else if (host_->getDuid()) { + dhcp_identifier_type_ = 1; // 1 = IDENT_DUID bind_[2].buffer_type = MYSQL_TYPE_TINY; - bind_[2].buffer = reinterpret_cast(1);// 1 = IDENT_DUID + bind_[2].buffer = reinterpret_cast(&dhcp_identifier_type_); bind_[2].is_unsigned = MLM_TRUE; // bind_[2].is_null = &MLM_FALSE; // commented out for performance // reasons, see memset() above } // dhcp4_subnet_id : INT UNSIGNED NULL + // Can't take an address of intermediate object, so let's store it + // in dhcp4_subnet_id_ + dhcp4_subnet_id_ = host_->getIPv4SubnetID(); bind_[3].buffer_type = MYSQL_TYPE_LONG; - bind_[3].buffer = reinterpret_cast(host_->getIPv4SubnetID()); + bind_[3].buffer = reinterpret_cast(&dhcp4_subnet_id_); bind_[3].is_unsigned = MLM_TRUE; // bind_[3].is_null = &MLM_FALSE; // commented out for performance // reasons, see memset() above // dhcp6_subnet_id : INT UNSIGNED NULL + // Can't take an address of intermediate object, so let's store it + // in dhcp6_subnet_id_ + dhcp6_subnet_id_ = host_->getIPv6SubnetID(); bind_[4].buffer_type = MYSQL_TYPE_LONG; - bind_[4].buffer = reinterpret_cast(host_->getIPv6SubnetID()); + bind_[4].buffer = reinterpret_cast(&dhcp6_subnet_id_); bind_[4].is_unsigned = MLM_TRUE; // bind_[4].is_null = &MLM_FALSE; // commented out for performance // reasons, see memset() above @@ -287,9 +295,11 @@ public: // reasons, see memset() above // hostname : VARCHAR(255) NULL + strncpy(hostname_, host_->getHostname().c_str(), HOSTNAME_MAX_LEN - 1); + hostname_length_ = host_->getHostname().length(); bind_[6].buffer_type = MYSQL_TYPE_STRING; - bind_[6].buffer = reinterpret_cast(host_->getHostname()[0]); - bind_[6].buffer_length = host_->getHostname().length(); + bind_[6].buffer = reinterpret_cast(hostname_); + bind_[6].buffer_length = hostname_length_; // bind_[6].is_null = &MLM_FALSE; // commented out for performance // reasons, see memset() above