From 1d6a2e3fb2715b445ce835847d7d353886495fea Mon Sep 17 00:00:00 2001 From: Tomek Mrugalski Date: Thu, 7 Feb 2013 15:28:36 +0100 Subject: [PATCH 1/3] [2697] Lease4::operator== is now safe to use for leases without client-id --- src/lib/dhcpsrv/lease_mgr.cc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/lib/dhcpsrv/lease_mgr.cc b/src/lib/dhcpsrv/lease_mgr.cc index 6608b14ddd..2310dd4cd5 100644 --- a/src/lib/dhcpsrv/lease_mgr.cc +++ b/src/lib/dhcpsrv/lease_mgr.cc @@ -113,11 +113,22 @@ Lease4::toText() const { bool Lease4::operator==(const Lease4& other) const { + if ( (client_id_ && !other.client_id_) || + (!client_id_ && other.client_id_) ) { + // One lease has client-id, but the other doesn't + return false; + } + + if (client_id_ && other.client_id_ && + *client_id_ != *other.client_id_) { + // Different client-ids + return false; + } + return ( addr_ == other.addr_ && ext_ == other.ext_ && hwaddr_ == other.hwaddr_ && - *client_id_ == *other.client_id_ && t1_ == other.t1_ && t2_ == other.t2_ && valid_lft_ == other.valid_lft_ && From b5e2be95d21ed750ad7cf5e15de2058aa8bc45f4 Mon Sep 17 00:00:00 2001 From: Tomek Mrugalski Date: Thu, 7 Feb 2013 16:58:41 +0100 Subject: [PATCH 2/3] [2697] Another fix for empty client-id, this time in MySQL LeaseMgr --- src/lib/dhcpsrv/mysql_lease_mgr.cc | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/lib/dhcpsrv/mysql_lease_mgr.cc b/src/lib/dhcpsrv/mysql_lease_mgr.cc index 292df616ad..6b6cde51d3 100644 --- a/src/lib/dhcpsrv/mysql_lease_mgr.cc +++ b/src/lib/dhcpsrv/mysql_lease_mgr.cc @@ -338,12 +338,25 @@ public: bind_[1].length = &hwaddr_length_; // client_id: varbinary(128) - client_id_ = lease_->client_id_->getClientId(); - client_id_length_ = client_id_.size(); - bind_[2].buffer_type = MYSQL_TYPE_BLOB; - bind_[2].buffer = reinterpret_cast(&client_id_[0]); - bind_[2].buffer_length = client_id_length_; - bind_[2].length = &client_id_length_; + if (lease_->client_id_) { + client_id_ = lease_->client_id_->getClientId(); + client_id_length_ = client_id_.size(); + bind_[2].buffer_type = MYSQL_TYPE_BLOB; + bind_[2].buffer = reinterpret_cast(&client_id_[0]); + bind_[2].buffer_length = client_id_length_; + bind_[2].length = &client_id_length_; + } else { + bind_[2].buffer_type = MYSQL_TYPE_NULL; + + // According to http://dev.mysql.com/doc/refman/5.5/en/ + // c-api-prepared-statement-data-structures.html, the other + // fields doesn't matter if type is set to MYSQL_TYPE_NULL, + // but let's set them to some sane values in case earlier versions + // didn't have that assumption. + static my_bool no_clientid = MLM_TRUE; + bind_[2].buffer = NULL; + bind_[2].is_null = &no_clientid; + } // valid lifetime: unsigned int bind_[3].buffer_type = MYSQL_TYPE_LONG; From dd2dbeb5a4507ba50ce1547972ab4ea1b56b4655 Mon Sep 17 00:00:00 2001 From: Tomek Mrugalski Date: Mon, 11 Feb 2013 14:41:18 +0100 Subject: [PATCH 3/3] [2697] ChangeLog updated. --- ChangeLog | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ChangeLog b/ChangeLog index 82082223ba..3986185aeb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +5XX. [bug] tomek + b10-dhcp4: Fix bug whereby a DHCP packet without a client ID + could crash the MySQL lease database backend. + (Trac #2697, git b5e2be95d21ed750ad7cf5e15de2058aa8bc45f4) + 566. [func]* jinmei libdns++/Python isc.dns: In Python isc.dns, function style constants for RRType, RRClass, Rcode and Opcode were deprecated