From nobody Mon Feb 9 10:49:25 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1614696623; cv=none; d=zohomail.com; s=zohoarc; b=DRiV6Q9BbtS/Y3xHJTXKFWjdgX6sEDBcrPitDvTy74OX/H8RkWD+xpsC7J5aEfKjm7s+KwMk0xmUihvuNdt5krbqFIzZ1v7Sh3iEk6a8u8EKy4ID2QAvbVA0elPuTvMO31PT2Xk16Km9+CqQbJKb4s+FvvV77JleQao+u21ABLo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614696623; 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=Gw7dJxfPvxmJvH4ibP9nveQ2uqFjuqihdKxoqlytAEA=; b=b8raamezvJZiwy/5MtEVnKPVSZRSvO4moGNaP7iqnP79BlN2yyUrddadyLfiGWyn/8IdP7NikuI765/QoTVROVUhnGvElkdA8GDlu20gsM05NexpDJjVhQxWQpj8mgQ7rnbx+3dOJGEaaXmu52PIjhF1+UTpehewpsXrtz6pMMA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1614696623555146.34734355352202; Tue, 2 Mar 2021 06:50:23 -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-302-WRyh2Q_uNh-NanM2mF7IjA-1; Tue, 02 Mar 2021 09:50:19 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 38FF918BA299; Tue, 2 Mar 2021 14:50:14 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 14EFC189C4; Tue, 2 Mar 2021 14:50:14 +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 C054D58087; Tue, 2 Mar 2021 14:50:13 +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 122EnpXl014537 for ; Tue, 2 Mar 2021 09:49:51 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7F5155D766; Tue, 2 Mar 2021 14:49:51 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id E6B3E5D722 for ; Tue, 2 Mar 2021 14:49:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614696622; 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=Gw7dJxfPvxmJvH4ibP9nveQ2uqFjuqihdKxoqlytAEA=; b=eheG8RQEojS4e8KrcPGScRsWjDkkS/jHy8PsO+JM+TM/pVimTR/MdPi9Xe0ie5laLFr5GP uIegvzYGvF2Q31Z9S+1/iSdAf8X754lU9Z8n+xndVHCuCtYyPnUHIzQe1tIToqI02BAQQs SH6D8zK4rfsLSWs46XHeeU6zQAF8C8c= X-MC-Unique: WRyh2Q_uNh-NanM2mF7IjA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 12/16] xenParseXLUSBController: Avoid use of virStrndup Date: Tue, 2 Mar 2021 15:49:29 +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.11 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" Use g_strndup with a freed buffer instead of the more complex approach using virStrndup. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/libxl/xen_xl.c | 51 ++++++++++------------------------------------ 1 file changed, 11 insertions(+), 40 deletions(-) diff --git a/src/libxl/xen_xl.c b/src/libxl/xen_xl.c index 9b2a2fe292..1bce31a549 100644 --- a/src/libxl/xen_xl.c +++ b/src/libxl/xen_xl.c @@ -885,16 +885,11 @@ xenParseXLUSBController(virConfPtr conf, virDomainDef= Ptr def) if (list && list->type =3D=3D VIR_CONF_LIST) { list =3D list->list; while (list) { - char type[8]; - char version[4]; - char ports[4]; char *key; int usbctrl_version =3D 2; /* by default USB 2.0 */ int usbctrl_ports =3D 8; /* by default 8 ports */ int usbctrl_type =3D -1; - type[0] =3D version[0] =3D ports[0] =3D '\0'; - if ((list->type !=3D VIR_CONF_STRING) || (list->str =3D=3D NUL= L)) goto skipusbctrl; /* usbctrl=3D['type=3Dpv,version=3D2,ports=3D8'] */ @@ -908,32 +903,19 @@ xenParseXLUSBController(virConfPtr conf, virDomainDef= Ptr def) data++; if (STRPREFIX(key, "type=3D")) { - int len =3D nextkey ? (nextkey - data) : strlen(data); - if (virStrncpy(type, data, len, sizeof(type)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("type %s invalid"), - data); + if (!STRPREFIX(data, "qusb")) goto skipusbctrl; - } } else if (STRPREFIX(key, "version=3D")) { int len =3D nextkey ? (nextkey - data) : strlen(data); - if (virStrncpy(version, data, len, sizeof(version)) < = 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("version %s invalid"), - data); - goto skipusbctrl; - } - if (virStrToLong_i(version, NULL, 16, &usbctrl_version= ) < 0) + g_autofree char *tmp =3D g_strndup(data, len); + + if (virStrToLong_i(tmp, NULL, 16, &usbctrl_version) < = 0) goto skipusbctrl; } else if (STRPREFIX(key, "ports=3D")) { int len =3D nextkey ? (nextkey - data) : strlen(data); - if (virStrncpy(ports, data, len, sizeof(ports)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("version %s invalid"), - data); - goto skipusbctrl; - } - if (virStrToLong_i(ports, NULL, 16, &usbctrl_ports) < = 0) + g_autofree char *tmp =3D g_strndup(data, len); + + if (virStrToLong_i(tmp, NULL, 16, &usbctrl_ports) < 0) goto skipusbctrl; } @@ -944,21 +926,10 @@ xenParseXLUSBController(virConfPtr conf, virDomainDef= Ptr def) key =3D nextkey; } - if (type[0] =3D=3D '\0') { - if (usbctrl_version =3D=3D 1) - usbctrl_type =3D VIR_DOMAIN_CONTROLLER_MODEL_USB_QUSB1; - else - usbctrl_type =3D VIR_DOMAIN_CONTROLLER_MODEL_USB_QUSB2; - } else { - if (STRPREFIX(type, "qusb")) { - if (usbctrl_version =3D=3D 1) - usbctrl_type =3D VIR_DOMAIN_CONTROLLER_MODEL_USB_Q= USB1; - else - usbctrl_type =3D VIR_DOMAIN_CONTROLLER_MODEL_USB_Q= USB2; - } else { - goto skipusbctrl; - } - } + if (usbctrl_version =3D=3D 1) + usbctrl_type =3D VIR_DOMAIN_CONTROLLER_MODEL_USB_QUSB1; + else + usbctrl_type =3D VIR_DOMAIN_CONTROLLER_MODEL_USB_QUSB2; if (!(controller =3D virDomainControllerDefNew(VIR_DOMAIN_CONT= ROLLER_TYPE_USB))) return -1; --=20 2.29.2