]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
network: fix crashing "modify" option for hostname
authorAdam Julis <ajulis@redhat.com>
Tue, 6 Aug 2024 07:01:42 +0000 (09:01 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 8 Aug 2024 10:36:36 +0000 (12:36 +0200)
The original condition caused (after adding modify option)
possibly access to not allocated memory. For consistency added
new check for multiple same records.

Resolves: https://gitlab.com/libvirt/libvirt/-/issues/654
Signed-off-by: Adam Julis <ajulis@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/conf/network_conf.c

index c23b0e440064ca6f03ef2d4460b9f3ae13579ccc..5cf419acf1d77a9a0bce3d36a0e3dab5e2ed82f0 100644 (file)
@@ -3167,7 +3167,7 @@ virNetworkDefUpdateDNSHost(virNetworkDef *def,
 
         /* when adding we want to only check duplicates of address since having
          * multiple addresses with the same hostname is a legitimate configuration */
-        if (!isAdd) {
+        if (command == VIR_NETWORK_UPDATE_COMMAND_DELETE) {
             for (j = 0; j < host.nnames && !foundThisTime; j++) {
                 for (k = 0; k < dns->hosts[i].nnames && !foundThisTime; k++) {
                     if (STREQ(host.names[j], dns->hosts[i].names[k]))
@@ -3224,6 +3224,13 @@ virNetworkDefUpdateDNSHost(virNetworkDef *def,
             goto cleanup;
         }
 
+        if (foundCt > 1) {
+            virReportError(VIR_ERR_OPERATION_INVALID,
+                           _("multiple matching DNS HOST records were found in network %1$s"),
+                           def->name);
+            goto cleanup;
+        }
+
         virNetworkDNSHostDefClear(&dns->hosts[foundIdxModify]);
 
         memcpy(&dns->hosts[foundIdxModify], &host, sizeof(virNetworkDNSHostDef));