mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-09-03 15:35:17 +00:00
[#53,!125] Ensure that the HW address and client id buffers are non-zero.
This commit is contained in:
@@ -464,14 +464,18 @@ public:
|
|||||||
if (hwaddr) {
|
if (hwaddr) {
|
||||||
hwaddr_ = hwaddr->hwaddr_;
|
hwaddr_ = hwaddr->hwaddr_;
|
||||||
hwaddr_length_ = hwaddr->hwaddr_.size();
|
hwaddr_length_ = hwaddr->hwaddr_.size();
|
||||||
bind_[1].buffer_type = MYSQL_TYPE_BLOB;
|
|
||||||
|
|
||||||
// Do not reference the buffer if it is empty and just leave it
|
// Make sure that the buffer has at least length of 1, even if
|
||||||
// set to 0 (memset set it to 0 above).
|
// empty HW address is passed. This is required by some of the
|
||||||
if (!hwaddr_.empty()) {
|
// MySQL connectors that the buffer is set to non-null value.
|
||||||
bind_[1].buffer = reinterpret_cast<char*>(&(hwaddr_[0]));
|
// Otherwise, null value would be inserted into the database,
|
||||||
|
// rather than empty string.
|
||||||
|
if (hwaddr_.empty()) {
|
||||||
|
hwaddr_.resize(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bind_[1].buffer_type = MYSQL_TYPE_BLOB;
|
||||||
|
bind_[1].buffer = reinterpret_cast<char*>(&(hwaddr_[0]));
|
||||||
bind_[1].buffer_length = hwaddr_length_;
|
bind_[1].buffer_length = hwaddr_length_;
|
||||||
bind_[1].length = &hwaddr_length_;
|
bind_[1].length = &hwaddr_length_;
|
||||||
} else {
|
} else {
|
||||||
@@ -490,14 +494,18 @@ public:
|
|||||||
if (lease_->client_id_) {
|
if (lease_->client_id_) {
|
||||||
client_id_ = lease_->client_id_->getClientId();
|
client_id_ = lease_->client_id_->getClientId();
|
||||||
client_id_length_ = client_id_.size();
|
client_id_length_ = client_id_.size();
|
||||||
bind_[2].buffer_type = MYSQL_TYPE_BLOB;
|
|
||||||
|
|
||||||
// Do not reference the buffer if it is empty and just leave it
|
// Make sure that the buffer has at least length of 1, even if
|
||||||
// set to 0 (memset set it to 0 above).
|
// empty HW address is passed. This is required by some of the
|
||||||
if (!client_id_.empty()) {
|
// MySQL connectors that the buffer is set to non-null value.
|
||||||
bind_[2].buffer = reinterpret_cast<char*>(&client_id_[0]);
|
// Otherwise, null value would be inserted into the database,
|
||||||
|
// rather than empty string.
|
||||||
|
if (client_id_.empty()) {
|
||||||
|
client_id_.resize(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bind_[2].buffer_type = MYSQL_TYPE_BLOB;
|
||||||
|
bind_[2].buffer = reinterpret_cast<char*>(&client_id_[0]);
|
||||||
bind_[2].buffer_length = client_id_length_;
|
bind_[2].buffer_length = client_id_length_;
|
||||||
bind_[2].length = &client_id_length_;
|
bind_[2].length = &client_id_length_;
|
||||||
// bind_[2].is_null = &MLM_FALSE; // commented out for performance
|
// bind_[2].is_null = &MLM_FALSE; // commented out for performance
|
||||||
@@ -1035,6 +1043,16 @@ public:
|
|||||||
if (hwaddr) {
|
if (hwaddr) {
|
||||||
hwaddr_ = hwaddr->hwaddr_;
|
hwaddr_ = hwaddr->hwaddr_;
|
||||||
hwaddr_length_ = hwaddr->hwaddr_.size();
|
hwaddr_length_ = hwaddr->hwaddr_.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
|
||||||
|
// MySQL connectors that the buffer is set to non-null value.
|
||||||
|
// Otherwise, null value would be inserted into the database,
|
||||||
|
// rather than empty string.
|
||||||
|
if (hwaddr_.empty()) {
|
||||||
|
hwaddr_.resize(1);
|
||||||
|
}
|
||||||
|
|
||||||
bind_[12].buffer_type = MYSQL_TYPE_BLOB;
|
bind_[12].buffer_type = MYSQL_TYPE_BLOB;
|
||||||
bind_[12].buffer = reinterpret_cast<char*>(&(hwaddr_[0]));
|
bind_[12].buffer = reinterpret_cast<char*>(&(hwaddr_[0]));
|
||||||
bind_[12].buffer_length = hwaddr_length_;
|
bind_[12].buffer_length = hwaddr_length_;
|
||||||
@@ -1912,20 +1930,20 @@ MySqlLeaseMgr::getLease4(const HWAddr& hwaddr) const {
|
|||||||
inbind[0].buffer_type = MYSQL_TYPE_BLOB;
|
inbind[0].buffer_type = MYSQL_TYPE_BLOB;
|
||||||
|
|
||||||
unsigned long hwaddr_length = hwaddr.hwaddr_.size();
|
unsigned long hwaddr_length = hwaddr.hwaddr_.size();
|
||||||
uint8_t* data = 0;
|
|
||||||
|
|
||||||
// Only reference the buffer if the buffer has any data. Otherwise
|
// If the data happens to be empty, we have to create a 1 byte dummy
|
||||||
// leave it set to 0 (memset set it to 0 above).
|
// buffer and pass it to the binding.
|
||||||
if (hwaddr_length > 0) {
|
std::vector<uint8_t> single_byte_vec(1);
|
||||||
// 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
|
|
||||||
// a "char*". (We could avoid the "const_cast" by copying the data to a
|
|
||||||
// local variable, but as the data is only being read, this introduces
|
|
||||||
// an unnecessary copy).
|
|
||||||
data = const_cast<uint8_t*>(&hwaddr.hwaddr_[0]);
|
|
||||||
inbind[0].buffer = reinterpret_cast<char*>(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// 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
|
||||||
|
// a "char*". (We could avoid the "const_cast" by copying the data to a
|
||||||
|
// local variable, but as the data is only being read, this introduces
|
||||||
|
// an unnecessary copy).
|
||||||
|
uint8_t* data = !hwaddr.hwaddr_.empty() ? const_cast<uint8_t*>(&hwaddr.hwaddr_[0])
|
||||||
|
: &single_byte_vec[0];
|
||||||
|
|
||||||
|
inbind[0].buffer = reinterpret_cast<char*>(data);
|
||||||
inbind[0].buffer_length = hwaddr_length;
|
inbind[0].buffer_length = hwaddr_length;
|
||||||
inbind[0].length = &hwaddr_length;
|
inbind[0].length = &hwaddr_length;
|
||||||
|
|
||||||
@@ -1949,20 +1967,20 @@ MySqlLeaseMgr::getLease4(const HWAddr& hwaddr, SubnetID subnet_id) const {
|
|||||||
inbind[0].buffer_type = MYSQL_TYPE_BLOB;
|
inbind[0].buffer_type = MYSQL_TYPE_BLOB;
|
||||||
|
|
||||||
unsigned long hwaddr_length = hwaddr.hwaddr_.size();
|
unsigned long hwaddr_length = hwaddr.hwaddr_.size();
|
||||||
uint8_t* data = 0;
|
|
||||||
|
|
||||||
// Only reference the buffer if the buffer has any data. Otherwise
|
// If the data happens to be empty, we have to create a 1 byte dummy
|
||||||
// leave it set to 0 (memset set it to 0 above).
|
// buffer and pass it to the binding.
|
||||||
if (hwaddr_length > 0) {
|
std::vector<uint8_t> single_byte_vec(1);
|
||||||
// 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
|
|
||||||
// a "char*". (We could avoid the "const_cast" by copying the data to a
|
|
||||||
// local variable, but as the data is only being read, this introduces
|
|
||||||
// an unnecessary copy).
|
|
||||||
data = const_cast<uint8_t*>(&hwaddr.hwaddr_[0]);
|
|
||||||
inbind[0].buffer = reinterpret_cast<char*>(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// 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
|
||||||
|
// a "char*". (We could avoid the "const_cast" by copying the data to a
|
||||||
|
// local variable, but as the data is only being read, this introduces
|
||||||
|
// an unnecessary copy).
|
||||||
|
uint8_t* data = !hwaddr.hwaddr_.empty() ? const_cast<uint8_t*>(&hwaddr.hwaddr_[0])
|
||||||
|
: &single_byte_vec[0];
|
||||||
|
|
||||||
|
inbind[0].buffer = reinterpret_cast<char*>(data);
|
||||||
inbind[0].buffer_length = hwaddr_length;
|
inbind[0].buffer_length = hwaddr_length;
|
||||||
inbind[0].length = &hwaddr_length;
|
inbind[0].length = &hwaddr_length;
|
||||||
|
|
||||||
@@ -1991,12 +2009,13 @@ MySqlLeaseMgr::getLease4(const ClientId& clientid) const {
|
|||||||
std::vector<uint8_t> client_data = clientid.getClientId();
|
std::vector<uint8_t> client_data = clientid.getClientId();
|
||||||
unsigned long client_data_length = client_data.size();
|
unsigned long client_data_length = client_data.size();
|
||||||
|
|
||||||
// Only reference the buffer if the buffer has any data. Otherwise
|
// If the data happens to be empty, we have to create a 1 byte dummy
|
||||||
// leave it set to 0 (memset set it to 0 above).
|
// buffer and pass it to the binding.
|
||||||
if (client_data_length > 0) {
|
if (client_data.empty()) {
|
||||||
inbind[0].buffer = reinterpret_cast<char*>(&client_data[0]);
|
client_data.resize(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inbind[0].buffer = reinterpret_cast<char*>(&client_data[0]);
|
||||||
inbind[0].buffer_length = client_data_length;
|
inbind[0].buffer_length = client_data_length;
|
||||||
inbind[0].length = &client_data_length;
|
inbind[0].length = &client_data_length;
|
||||||
|
|
||||||
@@ -2027,16 +2046,18 @@ MySqlLeaseMgr::getLease4(const ClientId& clientid, SubnetID subnet_id) const {
|
|||||||
MYSQL_BIND inbind[2];
|
MYSQL_BIND inbind[2];
|
||||||
memset(inbind, 0, sizeof(inbind));
|
memset(inbind, 0, sizeof(inbind));
|
||||||
|
|
||||||
std::vector<uint8_t> client_data = clientid.getClientId();
|
|
||||||
unsigned long client_data_length = client_data.size();
|
|
||||||
inbind[0].buffer_type = MYSQL_TYPE_BLOB;
|
inbind[0].buffer_type = MYSQL_TYPE_BLOB;
|
||||||
|
|
||||||
// Only reference the buffer if the buffer has any data. Otherwise
|
std::vector<uint8_t> client_data = clientid.getClientId();
|
||||||
// leave it set to 0 (memset set it to 0 above).
|
unsigned long client_data_length = client_data.size();
|
||||||
if (client_data_length > 0) {
|
|
||||||
inbind[0].buffer = reinterpret_cast<char*>(&client_data[0]);
|
// If the data happens to be empty, we have to create a 1 byte dummy
|
||||||
|
// buffer and pass it to the binding.
|
||||||
|
if (client_data.empty()) {
|
||||||
|
client_data.resize(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inbind[0].buffer = reinterpret_cast<char*>(&client_data[0]);
|
||||||
inbind[0].buffer_length = client_data_length;
|
inbind[0].buffer_length = client_data_length;
|
||||||
inbind[0].length = &client_data_length;
|
inbind[0].length = &client_data_length;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user