From: Tomek Mrugalski Date: Fri, 13 Nov 2015 08:50:57 +0000 (+0100) Subject: [3682] Segfault fix in HostDataSource::get4(subnet, hwaddr, duid) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5f7dd79dfb8a6b34c9d93ebd06af8e0df79ffee7;p=thirdparty%2Fkea.git [3682] Segfault fix in HostDataSource::get4(subnet, hwaddr, duid) --- diff --git a/src/lib/dhcpsrv/mysql_host_data_source.cc b/src/lib/dhcpsrv/mysql_host_data_source.cc index e34a316f97..906bb4a112 100644 --- a/src/lib/dhcpsrv/mysql_host_data_source.cc +++ b/src/lib/dhcpsrv/mysql_host_data_source.cc @@ -762,9 +762,20 @@ MySqlHostDataSource::get4(const SubnetID& subnet_id, MYSQL_BIND inbind[2]; memset(inbind, 0, sizeof(inbind)); - inbind[0].buffer_type = MYSQL_TYPE_LONG; - inbind[0].buffer = reinterpret_cast(subnet_id); - inbind[0].is_unsigned = MLM_TRUE; + uint32_t subnet_buffer = static_cast(subnet_id); + inbind[0].buffer_type = MYSQL_TYPE_LONG; + inbind[0].buffer = reinterpret_cast(&subnet_buffer); + inbind[0].is_unsigned = MLM_TRUE; + + /// @todo: Rethink the logic in BaseHostDataSource::get4(subnet, hwaddr, duid) + if (hwaddr && duid) { + isc_throw(BadValue, "MySQL host data source get4() called with both" + " hwaddr and duid, only one of them is allowed"); + } + if (!hwaddr && !duid) { + isc_throw(BadValue, "MySQL host data source get4() called with " + "neither hwaddr or duid specified, one of them is required"); + } // Choosing one of the identifiers if (hwaddr) {