From 038eddbc7b904289e4b74b5ef2406cb57f79a646 Mon Sep 17 00:00:00 2001 From: Marcin Siodelski Date: Fri, 16 Nov 2018 20:27:21 +0100 Subject: [PATCH] [#53,!125] Mysql buffer always initialized for HW address in v6. --- src/lib/dhcpsrv/mysql_lease_mgr.cc | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/lib/dhcpsrv/mysql_lease_mgr.cc b/src/lib/dhcpsrv/mysql_lease_mgr.cc index 6e241fe174..a663e781af 100644 --- a/src/lib/dhcpsrv/mysql_lease_mgr.cc +++ b/src/lib/dhcpsrv/mysql_lease_mgr.cc @@ -496,7 +496,7 @@ public: client_id_length_ = client_id_.size(); // Make sure that the buffer has at least length of 1, even if - // empty HW address is passed. This is required by some of the + // empty client id is passed. This is required by some of the // MySQL connectors that the buffer is set to non-null value. // Otherwise, null value would be inserted into the database, // rather than empty string. @@ -1933,7 +1933,7 @@ MySqlLeaseMgr::getLease4(const HWAddr& hwaddr) const { // If the data happens to be empty, we have to create a 1 byte dummy // buffer and pass it to the binding. - std::vector single_byte_vec(1); + uint8_t single_byte_data = 0; // As "buffer" is "char*" - even though the data is being read - we need // to cast away the "const"ness as well as reinterpreting the data as @@ -1941,7 +1941,7 @@ MySqlLeaseMgr::getLease4(const HWAddr& hwaddr) const { // local variable, but as the data is only being read, this introduces // an unnecessary copy). uint8_t* data = !hwaddr.hwaddr_.empty() ? const_cast(&hwaddr.hwaddr_[0]) - : &single_byte_vec[0]; + : &single_byte_data; inbind[0].buffer = reinterpret_cast(data); inbind[0].buffer_length = hwaddr_length; @@ -2197,9 +2197,18 @@ MySqlLeaseMgr::getLeases6(Lease::Type lease_type, // data). For that reason, "const_cast" has been used. const vector& duid_vector = duid.getDuid(); unsigned long duid_length = duid_vector.size(); + + // Make sure that the buffer has at least length of 1, even if + // empty client id is passed. This is required by some of the + // MySQL connectors that the buffer is set to non-null value. + // Otherwise, null value would be inserted into the database, + // rather than empty string. + uint8_t single_byte_data = 0; + uint8_t* data = !duid_vector.empty() ? const_cast(&duid_vector[0]) + : &single_byte_data; + inbind[0].buffer_type = MYSQL_TYPE_BLOB; - inbind[0].buffer = reinterpret_cast( - const_cast(&duid_vector[0])); + inbind[0].buffer = reinterpret_cast(data); inbind[0].buffer_length = duid_length; inbind[0].length = &duid_length; -- 2.47.2