]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3682] Segfault fix in HostDataSource::get4(subnet, hwaddr, duid)
authorTomek Mrugalski <tomasz@isc.org>
Fri, 13 Nov 2015 08:50:57 +0000 (09:50 +0100)
committerTomek Mrugalski <tomasz@isc.org>
Fri, 13 Nov 2015 08:50:57 +0000 (09:50 +0100)
src/lib/dhcpsrv/mysql_host_data_source.cc

index e34a316f97e67e2ee7d13d7e98c5ee1dbcd11ecf..906bb4a112157a17213d34ae3bce0c8fcd52177e 100644 (file)
@@ -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<char*>(subnet_id);
-       inbind[0].is_unsigned = MLM_TRUE;
+    uint32_t subnet_buffer = static_cast<uint32_t>(subnet_id);
+    inbind[0].buffer_type = MYSQL_TYPE_LONG;
+    inbind[0].buffer = reinterpret_cast<char*>(&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) {