From: Adam Julis Date: Tue, 6 Aug 2024 07:01:42 +0000 (+0200) Subject: network: fix crashing "modify" option for hostname X-Git-Tag: v10.7.0-rc1~73 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f3e670ee6b90d480b94e7310308c598289642672;p=thirdparty%2Flibvirt.git network: fix crashing "modify" option for hostname 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 Reviewed-by: Michal Privoznik --- diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index c23b0e4400..5cf419acf1 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -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));