From nobody Mon Feb 9 12:29:39 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1614696619; cv=none; d=zohomail.com; s=zohoarc; b=F2A0aVuHrVhIHJZcUWYpNMcSmFQEWvXCvUHz9aKNLl8g7ozC6Dxpx5Xuvu4oMWzP1AJBb3PPh7y34DBkdg68rsoJLKCYAl928vHmO9FK/RRJhHwXFicFxOAN1RbAw2+U+fPT6hldRYrMtCZJwc50rMKM+NHB3XCO9bL5IsW/W5o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614696619; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=zz/q1EJD1udbKupzzLeFjn4Vb4VUUGJNAblO9Ptip0I=; b=Nzgu1h1J17WIJsT57qLro1gg18ySheqLNwTzGbx+56WfIVNZbLMB4aJE5ozCeMypKXmrBgsIZCp1/Yk8kAd/7Zp8XjKvOH20lrBBhO/ydA9ynqY4kK6ZK5LrxwmUdKvNheel5OPIKKxQwumtPRTphB3MMjM6eHU/rBZppuzTInA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1614696619190810.961829957177; Tue, 2 Mar 2021 06:50:19 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-105-SOY3Gp7MOLiAfpeUeHlg5g-1; Tue, 02 Mar 2021 09:50:15 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1B99318B9EED; Tue, 2 Mar 2021 14:50:05 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E676E6F973; Tue, 2 Mar 2021 14:50:04 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 9776D18089D9; Tue, 2 Mar 2021 14:50:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 122Enn3b014516 for ; Tue, 2 Mar 2021 09:49:49 -0500 Received: by smtp.corp.redhat.com (Postfix) id 6EC345D768; Tue, 2 Mar 2021 14:49:49 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id C191B5D722 for ; Tue, 2 Mar 2021 14:49:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614696618; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=zz/q1EJD1udbKupzzLeFjn4Vb4VUUGJNAblO9Ptip0I=; b=TMA9TEU4jeo9jf6SSCgrc+Cw0dLnRQHKtmyhCDQOfcRDpk+MfPQLrLdCW4L0qpslxUvJAm 0bcheMCBVgeQJ8Z6D9RhMsjrkws5bzHmzYK9zoKPRh4XiDGAnDMUUkMmJ3nyrYA0loABag 3lnYUHHMzeF2pwMQwSKMOwH3Ix+agp8= X-MC-Unique: SOY3Gp7MOLiAfpeUeHlg5g-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 10/16] openvzReadNetworkConf: Rework parser Date: Tue, 2 Mar 2021 15:49:27 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Rewrite so that the parser doesn't use virStrncpy by employing g_strsplit. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/openvz/openvz_conf.c | 77 ++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 51 deletions(-) diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index 041a031a3a..836885af18 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -230,82 +230,57 @@ openvzReadNetworkConf(virDomainDefPtr def, veid); goto error; } else if (ret > 0) { - token =3D strtok_r(temp, ";", &saveptr); - while (token !=3D NULL) { - char *p =3D token; - char cpy_temp[32]; - int len; + g_auto(GStrv) devices =3D g_strsplit(temp, ";", 0); + GStrv device; - /* add new device to list */ - net =3D g_new0(virDomainNetDef, 1); + for (device =3D devices; device && *device; device++) { + g_auto(GStrv) keyvals =3D g_strsplit(*device, ",", 0); + GStrv keyval; + net =3D g_new0(virDomainNetDef, 1); net->type =3D VIR_DOMAIN_NET_TYPE_BRIDGE; - /* parse string */ - do { - char *next =3D strchr(p, ','); - if (!next) - next =3D strchr(p, '\0'); - if (STRPREFIX(p, "ifname=3D")) { + for (keyval =3D keyvals; keyval && *keyval; keyval++) { + char *val =3D strchr(*keyval, '=3D'); + + if (!val) + continue; + + val++; + + if (STRPREFIX(*keyval, "ifname=3D")) { /* skip in libvirt */ - } else if (STRPREFIX(p, "host_ifname=3D")) { - p +=3D 12; - len =3D next - p; - if (len > 16) { + } else if (STRPREFIX(*keyval, "host_ifname=3D")) { + if (strlen(val) > 16) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Too long network device name")); goto error; } - net->ifname =3D g_new0(char, len+1); - - if (virStrncpy(net->ifname, p, len, len+1) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Network ifname %s too long for d= estination"), p); - goto error; - } - } else if (STRPREFIX(p, "bridge=3D")) { - p +=3D 7; - len =3D next - p; - if (len > 16) { + net->ifname =3D g_strdup(val); + } else if (STRPREFIX(*keyval, "bridge=3D")) { + if (strlen(val) > 16) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Too long bridge device name")); goto error; } - net->data.bridge.brname =3D g_new0(char, len+1); - - if (virStrncpy(net->data.bridge.brname, p, len, len+1)= < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Bridge name %s too long for dest= ination"), p); - goto error; - } - } else if (STRPREFIX(p, "mac=3D")) { - p +=3D 4; - len =3D next - p; - if (len !=3D 17) { /* should be 17 */ + net->data.bridge.brname =3D g_strdup(val); + } else if (STRPREFIX(*keyval, "mac=3D")) { + if (strlen(val) !=3D 17) { /* should be 17 */ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Wrong length MAC address")); goto error; } - if (virStrncpy(cpy_temp, p, len, sizeof(cpy_temp)) < 0= ) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("MAC address %s too long for dest= ination"), p); - goto error; - } - if (virMacAddrParse(cpy_temp, &net->mac) < 0) { + if (virMacAddrParse(val, &net->mac) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Wrong MAC address")); goto error; } } - p =3D ++next; - } while (p < token + strlen(token)); - - if (VIR_APPEND_ELEMENT_COPY(def->nets, def->nnets, net) < 0) - goto error; + } - token =3D strtok_r(NULL, ";", &saveptr); + ignore_value(VIR_APPEND_ELEMENT_COPY(def->nets, def->nnets, ne= t)); } } --=20 2.29.2