From nobody Sat May 4 04:35:24 2024 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=1614697171; cv=none; d=zohomail.com; s=zohoarc; b=DKnznZnNVUOq0uiLIT7ytU0I/L+Mg7YB/3+EOiLF+KtwYOKHvKlFi9eUB10rwZQ0Vv1R8rYRA8Qk/Ok5Tdr3VTUiXIJ9UrJ4NAgqzpOXBEbe7O9DP/AUKTCvrHdSqISY7XDQYq4PLAB97dseb08uz0sllqgiX4sOxi8Fr1Np2a8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614697171; 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=YADQIvFcjg3j8Sz0S19cEefss95zrkW2MvNIpFdjmfI=; b=DiH81c3DwGDCaecYEKIAqhoKvNp1v5z+y5h3PZQMku0O9mmd4caE9qFkThPjatdK8UoMjgJgZokxYFH3mTnhl2oPc6DV1W7xp8CpCmm1FmQoJLpHIzWbf5+FB2omivzK52gEwtLLre892F7Ke9RaFbpw/o3R6vCifmZQL2EpDjw= 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 1614697170981355.608826086631; Tue, 2 Mar 2021 06:59:30 -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-268-H7sNJn_1MGaN0oSIZ2_3oQ-1; Tue, 02 Mar 2021 09:55:59 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 420EE803F4A; Tue, 2 Mar 2021 14:49:45 +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 85B1F5B6A7; Tue, 2 Mar 2021 14:49:43 +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 BE61718095CB; Tue, 2 Mar 2021 14:49:40 +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 122Endn0014401 for ; Tue, 2 Mar 2021 09:49:39 -0500 Received: by smtp.corp.redhat.com (Postfix) id 5D22B5D723; Tue, 2 Mar 2021 14:49:39 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id BF7E35D722 for ; Tue, 2 Mar 2021 14:49:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614697169; 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=YADQIvFcjg3j8Sz0S19cEefss95zrkW2MvNIpFdjmfI=; b=I4GaCmbT0XSmCmz+fEUyP/JBmd54oGTT9V8AOcuI1r2gXzK9IGe4ThyVbW7x6oHItD4fBF VJ+aQYSEm2Eq/fTWzBRpg0+29lvK5Vc09w8n0LCKCN4UM/IvvuKTi656QeILE844cQTy33 hOxziaInY5KJf8T0IbkhGp9sRNv0Uxg= X-MC-Unique: H7sNJn_1MGaN0oSIZ2_3oQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 01/16] util: virstring: Always copy string in virStrcpy Date: Tue, 2 Mar 2021 15:49:18 +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.15 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" 15 out of 72 invocations of virStrcpy(Static) ignore the return value as it's either impossible to fail or in certain cases a truncated copy is still good enough. Unfortunately virStrcpy doesn't copy anything in such case as the checks are done first. Fix this by using g_strlcpy for the implementation and removing G_GNUC_WARN_UNUSED_RESULT from the function so that callers can decide when it's okay. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virstring.c | 12 +++++++----- src/util/virstring.h | 3 +-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/util/virstring.c b/src/util/virstring.c index c3e64007fe..a35cd8ba76 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -503,16 +503,18 @@ virStrncpy(char *dest, const char *src, size_t n, siz= e_t destbytes) * @src: source buffer * @destbytes: number of bytes the destination can accommodate * - * Copies @src to @dest. + * Copies @src to @dest. @dest is guaranteed to be 'nul' terminated if + * destbytes is 1 or more. * - * See virStrncpy() for more information. - * - * Returns: 0 on success, <0 on failure. + * Returns: 0 on success, -1 if @src doesn't fit into @dest and was trunca= ted. */ int virStrcpy(char *dest, const char *src, size_t destbytes) { - return virStrncpy(dest, src, -1, destbytes); + if (g_strlcpy(dest, src, destbytes) >=3D destbytes) + return -1; + + return 0; } /** diff --git a/src/util/virstring.h b/src/util/virstring.h index 45aead1838..da1fe86ffc 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -99,8 +99,7 @@ bool virStringIsEmpty(const char *str); int virStrncpy(char *dest, const char *src, size_t n, size_t destbytes) G_GNUC_WARN_UNUSED_RESULT; -int virStrcpy(char *dest, const char *src, size_t destbytes) - G_GNUC_WARN_UNUSED_RESULT; +int virStrcpy(char *dest, const char *src, size_t destbytes); #define virStrcpyStatic(dest, src) virStrcpy((dest), (src), sizeof(dest)) int virStringSortCompare(const void *a, const void *b); --=20 2.29.2 From nobody Sat May 4 04:35:24 2024 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=1614696593; cv=none; d=zohomail.com; s=zohoarc; b=nJGPJEBTL47GBhkNRKdIs5Es5e1nRmPds6qVNzWzhUMsHjk+XvRao3PineM7rfzZb9p+UjhzhG2n9aTm+TouktRRFmx33bMJmOOlfO7SkBamW/c7IOD/cHITJti15Zc7q5QHSLwDPOP2erDBNQ6IU091SZNSvYzEMUVvd4oSo2c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614696593; 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=907phQNNu0M+wLS/IfyXkQcEL8XuSaABY1lMtOF5OyE=; b=fCGT7KTla9N23wT2O570nFGS7z6kWYNEkIesaJzMx5hGOd+MKG2yxxb65YGblk7e6LBcvvdeh2Ct9KcsSs25oB6XeilY8wqQBmS3ZuNlHcpuuT9yCXeNitiWQCXTG7NykOpBlHptDsQdMK+D3IVoKQl9nJp5rK3xjRscCUDnc2I= 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 1614696593535496.4512097414196; Tue, 2 Mar 2021 06:49:53 -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-520-uAIRgRDzMMC96kXMVKv60A-1; Tue, 02 Mar 2021 09:49:50 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 324F7803F48; Tue, 2 Mar 2021 14:49:45 +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 C5B275C626; Tue, 2 Mar 2021 14:49:44 +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 741EE49; Tue, 2 Mar 2021 14:49:43 +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 122Enet5014411 for ; Tue, 2 Mar 2021 09:49:40 -0500 Received: by smtp.corp.redhat.com (Postfix) id 665095D723; Tue, 2 Mar 2021 14:49:40 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id BFF325D722 for ; Tue, 2 Mar 2021 14:49:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614696592; 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=907phQNNu0M+wLS/IfyXkQcEL8XuSaABY1lMtOF5OyE=; b=T3+gBI4NUoRxNdWEwxSSHVcQp/FOg1wAxVjrgKcLHjsONBxpwtfbbDDvq3z4n1nwbSeHtH HvdCBgNEPnGOhDfQ1bfyG9X1hihx2152bq2LFvdprWG+xBjkVGL/T+slUCnrYU1KRfcbPe QkLhe9Ej44uu7SvKqixrEHli4wB/koY= X-MC-Unique: uAIRgRDzMMC96kXMVKv60A-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 02/16] virProcessRunInForkHelper: Use virStrcpyStatic for static buffers Date: Tue, 2 Mar 2021 15:49:19 +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.16 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" Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virprocess.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/util/virprocess.c b/src/util/virprocess.c index 69d64e9466..7a0960e337 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -1168,14 +1168,14 @@ virProcessRunInForkHelper(int errfd, bin->data.code =3D err->code; bin->data.domain =3D err->domain; - ignore_value(virStrcpy(bin->data.message, err->message, sizeof= (bin->data.message))); + virStrcpyStatic(bin->data.message, err->message); bin->data.level =3D err->level; if (err->str1) - ignore_value(virStrcpy(bin->data.str1, err->str1, sizeof(b= in->data.str1))); + virStrcpyStatic(bin->data.str1, err->str1); if (err->str2) - ignore_value(virStrcpy(bin->data.str2, err->str2, sizeof(b= in->data.str2))); + virStrcpyStatic(bin->data.str2, err->str2); if (err->str3) - ignore_value(virStrcpy(bin->data.str3, err->str3, sizeof(b= in->data.str3))); + virStrcpyStatic(bin->data.str3, err->str3); bin->data.int1 =3D err->int1; bin->data.int2 =3D err->int2; --=20 2.29.2 From nobody Sat May 4 04:35:24 2024 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=1614696611; cv=none; d=zohomail.com; s=zohoarc; b=jrSTp6Tw35EdqlPUaQA6QAq9Zcg1WxPOCz2PWK50A4PsXmdsVoppXNBWtSKcGkTPLnoreEI9JxIbsXvH9zSXwLhYSDHHAQyAJyOmpXwIQTawtca1PKyNicVl3bzZQtY2V/0rItVzuQIHjZka9g4xE9kNhPxyKnwnTFFssU7DvQ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614696611; 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=JIQTYJjo+ch9lyNZiG1oZlC2hbeyB5N8LzpgPsQFKk8=; b=Fw4J/3H0sovs+2v6+zQXnOWoH2T5VTqz/5dP9fnNz6G7UPaIGipyN4Jsf/D/bvkCcZ6Ta4i79c9B9hzW282HAv1kPn0nJ+7SQkNDYE/Mps7uhepPe35f1pUpvqFAD3jDF2nPy1+XZlSe/z57UfaOX6ssptul4VF2jId3o5Rlybs= 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 1614696611828687.0906246333245; Tue, 2 Mar 2021 06:50:11 -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-365-IxpXQy0zMPqKng_yKNuuag-1; Tue, 02 Mar 2021 09:50:04 -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 423D0107ACE6; Tue, 2 Mar 2021 14:49:58 +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 1A6A0189C4; Tue, 2 Mar 2021 14:49:58 +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 D25EF49; Tue, 2 Mar 2021 14:49:57 +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 122EnfDb014421 for ; Tue, 2 Mar 2021 09:49:41 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7029E5D723; Tue, 2 Mar 2021 14:49:41 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id D15515D722 for ; Tue, 2 Mar 2021 14:49:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614696610; 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=JIQTYJjo+ch9lyNZiG1oZlC2hbeyB5N8LzpgPsQFKk8=; b=Fdo62iIYUtOVGXHgSe7QTnhFLmcOVbkbBTW5G7G2239oddX8UBk1pVisDhuLpJiE97f3AG O8Sndq1meVTAdm7sPSe/AkXZcMJ7FxpPCVZktifJejrejYR4Bq1eyvsExADt9IG2018VXp cRdKP1tbahmQz0PDuuEbB/xT5BC8UVI= X-MC-Unique: IxpXQy0zMPqKng_yKNuuag-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 03/16] sanlock: Use virStrcpy instead of virStrncpy Date: Tue, 2 Mar 2021 15:49:20 +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" We want a (possibly truncated) copy of the full source string so virStrcpy is a better fit. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/locking/lock_driver_sanlock.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/locking/lock_driver_sanlock.c b/src/locking/lock_driver_sa= nlock.c index aaffe30e6f..1d8f109375 100644 --- a/src/locking/lock_driver_sanlock.c +++ b/src/locking/lock_driver_sanlock.c @@ -924,9 +924,7 @@ static int virLockManagerSanlockAcquire(virLockManagerP= tr lock, /* sanlock doesn't use owner_name for anything, so it's safe to take j= ust * the first SANLK_NAME_LEN - 1 characters from vm_name */ - ignore_value(virStrncpy(opt->owner_name, priv->vm_name, - MIN(strlen(priv->vm_name), SANLK_NAME_LEN - 1), - SANLK_NAME_LEN)); + virStrcpy(opt->owner_name, priv->vm_name, SANLK_NAME_LEN); if (state && STRNEQ(state, "")) { if ((rv =3D sanlock_state_to_args((char *)state, --=20 2.29.2 From nobody Sat May 4 04:35:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1614696607; cv=none; d=zohomail.com; s=zohoarc; b=htyRlQxd0lTks8+qZUsp0nzbSEOP25QbPqnpusEj8KrUKIL+Y67+c3kACXfWtdGu1O9tqs/kVT+6TQSyiHRqCb7vSGYT0DwK8aZkKqBOp7e16zAbB+GIRUOJTcOfBVqybg/dobDQzJkuSmkRlOvAgGoCg7bi3tinOvvFOUyGftw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614696607; 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=hclxgyPDhp2X6FrRFeFcGfEBVxTefIdRRtWv9VVsovM=; b=moCcjW72VeRs0B1ABn82PW54tNsIFZtNv5H8fuR31ek1koPB4KErjPSSRRzyKAEZIGPxuuMDxtneV6TfnoezNzecR7SYmjPBH9szBVmv5rtz9yDE4zkUbv2vPGhOC3jlYkCtYGze8MK5zBvVfxBeu0zr2riSgfBbvnRKPK2hiuY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 1614696607620982.062849215813; Tue, 2 Mar 2021 06:50:07 -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-36-bUL6hJJXOqKfH3cPJA9QKA-1; Tue, 02 Mar 2021 09:50:04 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4331718B9ECA; Tue, 2 Mar 2021 14:49:58 +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 1DEB95C6AB; Tue, 2 Mar 2021 14:49:58 +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 D56F11809C8F; Tue, 2 Mar 2021 14:49:57 +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 122EngFf014431 for ; Tue, 2 Mar 2021 09:49:42 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8473D5D723; Tue, 2 Mar 2021 14:49:42 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id DAAD55D722 for ; Tue, 2 Mar 2021 14:49:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614696606; 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=hclxgyPDhp2X6FrRFeFcGfEBVxTefIdRRtWv9VVsovM=; b=c1wDImKapoBkkZtfYTFqk9ACju+uUoZv3A4WRKyuuFSleVY5M2GSATNaDgxHzZ9ZXoCEFi cOhsxu+zTPvyqVkHF9rlbTs2Ci1NnZSnm5j6goY74+v9TJckEfq9kjGqARA3qqADZAqLCn mim2pE3fADol/bIyHyd+s8vF3Ve8CFE= X-MC-Unique: bUL6hJJXOqKfH3cPJA9QKA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 04/16] virDevMapperGetTargetsImpl: Use virStrcpy instead of virStrncpy Date: Tue, 2 Mar 2021 15:49:21 +0100 Message-Id: <0fefcaa1662185402170904206dafce0150bf0c6.1614696480.git.pkrempa@redhat.com> 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.16 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" virStrncpy was called with -1 for lenght of the copied source which is equivalent to virStrcpy. Signed-off-by: Peter Krempa --- src/util/virdevmapper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/virdevmapper.c b/src/util/virdevmapper.c index d97334bf67..fcb11e954f 100644 --- a/src/util/virdevmapper.c +++ b/src/util/virdevmapper.c @@ -240,7 +240,7 @@ virDevMapperGetTargetsImpl(int controlFD, if (!(sanitizedPath =3D virDMSanitizepath(path))) return 0; - if (virStrncpy(dm.name, sanitizedPath, -1, DM_TABLE_DEPS) < 0) { + if (virStrcpy(dm.name, sanitizedPath, DM_TABLE_DEPS) < 0) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", _("Resolved device mapper name too long")); return -1; --=20 2.29.2 From nobody Sat May 4 04:35:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1614696681; cv=none; d=zohomail.com; s=zohoarc; b=cCgeo3qYmSam7qxaiA5vDNUXG+79hPkYN3qyaTlwsLJYCiakbAFlkqvdCbJl82L9iikYtUeouwtoYvN8OfzqxZOHfJkCLjTHior9ow481xDbj8cbb4jlsK1pd5o/XIDYrgso4/y3Ew44dwVrEPfUDAHVbNZWiAG4rsdRqnaIZKU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614696681; 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=fdEdJfaajFI9o7uGv0PkZIkY0vmUiCyryPZIvu14XvU=; b=DwDffWdcAzG2TIMb8VZMD8h8xewKryZx/05TZA3lAsLbDKO0i/nIuMJNQsE+ypT/GAdmgz6Blex34Xz1CZt3sZopfp33QoY1kWpQFceFESSyhHgC5k3BMSkr/9alLZj+y26njlGp/YNMo2seEgZw+Y7cEkeRyxDvLgiTlUf4Et0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 1614696681955270.5910460794788; Tue, 2 Mar 2021 06:51:21 -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-124-q9MUiERUNQquzblSIQAugA-1; Tue, 02 Mar 2021 09:50:10 -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 AB68380198B; Tue, 2 Mar 2021 14:50:01 +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 3FB296EF54; Tue, 2 Mar 2021 14:50:01 +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 F41A158078; Tue, 2 Mar 2021 14:50:00 +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 122EnhNZ014441 for ; Tue, 2 Mar 2021 09:49:43 -0500 Received: by smtp.corp.redhat.com (Postfix) id 9706C5D722; Tue, 2 Mar 2021 14:49:43 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id EE3E05B69C for ; Tue, 2 Mar 2021 14:49:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614696680; 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=fdEdJfaajFI9o7uGv0PkZIkY0vmUiCyryPZIvu14XvU=; b=Leg52FSKIG1Gc6X5t/sXNEc6BmX6nGYR728WqDVim32TVYXpmaEQdnjQyWaeLGcKF2lzN4 yCuxzqkpvgWq5g67K7HPn+NG1pARcDegXwIN1/gb1UB3rddNu7DIz4w4G4t7omA9mMgt4A 7Itpz+svo3wQ+I/6e6t5bgEf2uHAd2E= X-MC-Unique: q9MUiERUNQquzblSIQAugA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 05/16] virFileLoopDeviceAssociate: Use virStrcpy instead of virStrncpy Date: Tue, 2 Mar 2021 15:49:22 +0100 Message-Id: <0203996e2f3ffbe650717ab2712e2bbb19957355.1614696480.git.pkrempa@redhat.com> 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" Passing 'strlen(src)' for length makes it equivalent to virStrcpy. Signed-off-by: Peter Krempa --- src/util/virfile.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index 841a0f4e00..29445fc0ff 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -810,8 +810,7 @@ int virFileLoopDeviceAssociate(const char *file, lo.lo_flags =3D LO_FLAGS_AUTOCLEAR; /* Set backing file name for LOOP_GET_STATUS64 queries */ - if (virStrncpy((char *) lo.lo_file_name, file, - strlen(file), LO_NAME_SIZE) < 0) { + if (virStrcpy((char *) lo.lo_file_name, file, LO_NAME_SIZE) < 0) { virReportSystemError(errno, _("Unable to set backing file %s"), file); goto cleanup; --=20 2.29.2 From nobody Sat May 4 04:35:24 2024 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=1614696607; cv=none; d=zohomail.com; s=zohoarc; b=dk6lqosDm7XB7ge+1xU7kJt+1aU7ZmHO0M09oJ173Mhp/OJkd4t9XyfMvgMIujPXX1BI7sdEKWszNTZOMxK5tun9EB2LOelQFqR8TvaNaDg9AnlEMG12lcFIBP32Y0fnH7vJ6kgN+LhP6SNaUIOcUXoKX0T6nu6eoGxiYmoMlKg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614696607; 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=D5VWaBjZTNoaRPfoZgB/Uyo7Wxww3Xpen/QydcVwjGc=; b=kqnZVi5PBEbcP3PE+FXXMbw3Z3KwCBMyju9wPzK7utP/pk9c2Yol67Xl4hBHPw30Qua/sWko+sEjHR7KBUEnSHsCf0p/ub09nl8JcnEpfJSH99d3kBOCRXGMu8hQ+aoxMcOIKfb9gLotscN67d25mqO6M3NdftELNfNQJj3oqCg= 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 1614696607966496.8035818433258; Tue, 2 Mar 2021 06:50:07 -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-322-oZdLuLorNlySGqhe3W2gqg-1; Tue, 02 Mar 2021 09:50:04 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4A36E50742; Tue, 2 Mar 2021 14:49:58 +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 2200F5D768; Tue, 2 Mar 2021 14:49:58 +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 DB4561809C90; Tue, 2 Mar 2021 14:49:57 +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 122EniH9014465 for ; Tue, 2 Mar 2021 09:49:44 -0500 Received: by smtp.corp.redhat.com (Postfix) id 9ECE25D723; Tue, 2 Mar 2021 14:49:44 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0D5A55D722 for ; Tue, 2 Mar 2021 14:49:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614696607; 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=D5VWaBjZTNoaRPfoZgB/Uyo7Wxww3Xpen/QydcVwjGc=; b=Wvqie2M3G+7PhXE6z7wEn77QCXkZKQJCCqYRPIVd8a/UtW0/pHIc5UYWuedmBBttjGllah Ec0hij9SPA8cdYkXn5/+w2u1As9ZoXRHoLfhH3/bNRwtAIM9QGYPjzh0n7G+RT8OUjk0Kd UTROoaPabouaJnhIgpxhR3Z+cFyXtmk= X-MC-Unique: oZdLuLorNlySGqhe3W2gqg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 06/16] xenParseXMDisk: Replace g_new + virStrncpy by g_strndup Date: Tue, 2 Mar 2021 15:49:23 +0100 Message-Id: <12e1ee3de5d96b6167f3cc1a899550ade71ed24a.1614696480.git.pkrempa@redhat.com> 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.15 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" Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/libxl/xen_xm.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/libxl/xen_xm.c b/src/libxl/xen_xm.c index 3e81c9ef0d..cc24317a76 100644 --- a/src/libxl/xen_xm.c +++ b/src/libxl/xen_xm.c @@ -146,14 +146,7 @@ xenParseXMDisk(char *entry, int hvm) if (!(offset =3D strchr(head, ','))) goto error; - disk->dst =3D g_new0(char, (offset - head) + 1); - - if (virStrncpy(disk->dst, head, offset - head, - (offset - head) + 1) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Dest file %s too big for destination"), head); - goto error; - } + disk->dst =3D g_strndup(head, offset - head); head =3D offset + 1; /* Extract source driver type */ --=20 2.29.2 From nobody Sat May 4 04:35:24 2024 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=1614696613; cv=none; d=zohomail.com; s=zohoarc; b=OVzfrCm3P8Esy7IJtnTMCi4sAXoHE+v0tuHpiWQvivoB2C2ak23ipZ9+uvLWrVL3LzW9WeFwXdph3Bw5jEH0zlgmAjc1cbjvSIgc1sRmeE9gGj7iVDusVT1EyUWUv/+INoD/aW4HXIHJFOUPMBp937ER/OMpZMvQJ+5Jg+HGM60= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614696613; 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=wVQZFiBFRbqvMm14q3WD07+HT+HA8Aee+aHJO+A5R8o=; b=LXCkBBdtTkqhPwMZ3hX7KYgozOrjtk8kGIn6+pRDIlyudcPvTlNhfvpHra74dn+T+CIUL4gMquJcT9HpqFpEKIG6XN4IYBI6FoybU1f+VYhU7F0du5VH6s0R5GK6ROiy7V1QjpO7RnJLDYijwNiQEOwbD8QnInM6/aI0sMtfK0s= 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 1614696613104743.0485591683441; Tue, 2 Mar 2021 06:50:13 -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-249-rxpRa94SPmKnqoxPcXUYyQ-1; Tue, 02 Mar 2021 09:50:08 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B8B94107ACFE; Tue, 2 Mar 2021 14:50:01 +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 73F2519708; Tue, 2 Mar 2021 14:50:01 +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 0795858079; Tue, 2 Mar 2021 14:50:01 +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 122Enjga014472 for ; Tue, 2 Mar 2021 09:49:45 -0500 Received: by smtp.corp.redhat.com (Postfix) id AC8A25D723; Tue, 2 Mar 2021 14:49:45 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 120E85D722 for ; Tue, 2 Mar 2021 14:49:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614696612; 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=wVQZFiBFRbqvMm14q3WD07+HT+HA8Aee+aHJO+A5R8o=; b=Ev0vGlMXiOqdgkoX68gKTx+xVJdcKCY+8rQuUnRBDvcT/mXi6wQ4Jd/ZIaIIM47ma2dYw/ RuRPWc1xzPTDY0slVaoKdeSndVTABTf5ZmHNrJXKsuXWKJDg8mdXpluaK6qEc1edKP+K8w ya+YNF8kZ9SV+DOLYTkaEx5nxr7Kuq4= X-MC-Unique: rxpRa94SPmKnqoxPcXUYyQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 07/16] test_driver: Rewrite testBuildFilename Date: Tue, 2 Mar 2021 15:49:24 +0100 Message-Id: <03a12c866ac3af0b1c277a9d01f73349448d1a59.1614696480.git.pkrempa@redhat.com> 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.84 on 10.5.11.23 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 glib functions to do the relative name lookup instead of manual assembly. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/test/test_driver.c | 35 ++++++----------------------------- 1 file changed, 6 insertions(+), 29 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 71ab04aa1a..30a1959589 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -739,32 +739,14 @@ testDomainStartState(testDriverPtr privconn, static char *testBuildFilename(const char *relativeTo, const char *filename) { - char *offset; - int baseLen; - char *ret; + g_autofree char *basename =3D NULL; - if (!filename || filename[0] =3D=3D '\0') - return NULL; - if (filename[0] =3D=3D '/') { - ret =3D g_strdup(filename); - return ret; - } + if (g_path_is_absolute(filename)) + return g_strdup(filename); - offset =3D strrchr(relativeTo, '/'); - if ((baseLen =3D (offset-relativeTo+1))) { - char *absFile; - int totalLen =3D baseLen + strlen(filename) + 1; - absFile =3D g_new0(char, totalLen); - if (virStrncpy(absFile, relativeTo, baseLen, totalLen) < 0) { - VIR_FREE(absFile); - return NULL; - } - strcat(absFile, filename); - return absFile; - } else { - ret =3D g_strdup(filename); - return ret; - } + basename =3D g_path_get_dirname(relativeTo); + + return g_strdup_printf("%s/%s", basename, filename); } static xmlNodePtr @@ -777,11 +759,6 @@ testParseXMLDocFromFile(xmlNodePtr node, const char *f= ile, const char *type) if ((relFile =3D virXMLPropString(node, "file"))) { absFile =3D testBuildFilename(file, relFile); - if (!absFile) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("resolving %s filename"), type); - return NULL; - } if (!(doc =3D virXMLParse(absFile, NULL, type))) goto error; --=20 2.29.2 From nobody Sat May 4 04:35:24 2024 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=1614696613; cv=none; d=zohomail.com; s=zohoarc; b=R7GAMdSAxGDP6U4cN+sIFqwOAXW58Jp5adGNC/IoouD92I5G+a4L32jSk9Z9iYTlRir2JuVpIZW99kZOjdCZXNOy1mADc1ms/fEgKNIjnIPT05I0IOhNLh4yIhapt0lMuP2svT3hwcia97s+75lVsRPFKNODlf6xUs1ukbDRScc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614696613; 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=iXWBdR5wO1UmRKWocksAJcVbTJA2jjCffPbGCfSazdk=; b=GkdeYIl2u7DkV9dUWPt7Y1y3gPinabIz+K7VkrnhVOt3uowhntiwKLAOrluLmkEoOV0fCJf55wvsQZ/HVpq74NcnJ+KaRyVghCEcR2NyUbmFL3D4LP/tMwb4sy8itxNYqihbQT10TZghW4ExFjU5J6x7cTCUoyKOybslFwCkwzo= 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 1614696613779194.6273356858926; Tue, 2 Mar 2021 06:50:13 -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-533-FHateh3eO7WYwGuF7cBlZA-1; Tue, 02 Mar 2021 09:50:10 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8F668801989; Tue, 2 Mar 2021 14:50:01 +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 4307C5D768; Tue, 2 Mar 2021 14:50:01 +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 F082318089C9; Tue, 2 Mar 2021 14:50:00 +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 122EnljJ014490 for ; Tue, 2 Mar 2021 09:49:47 -0500 Received: by smtp.corp.redhat.com (Postfix) id 03D6B5D723; Tue, 2 Mar 2021 14:49:47 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2AA605D722 for ; Tue, 2 Mar 2021 14:49:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614696612; 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=iXWBdR5wO1UmRKWocksAJcVbTJA2jjCffPbGCfSazdk=; b=gx/oY8pqom0GLp6Szhu/QFTDABYNr6Codc5G7KF5AVPhQD/um4Z91FLSsm3Hb6IVrKyKpq p+5YgXkMFrLU0WNPlbjWftb4wextoBZ9/C3tWxF3ge54xjjMkNCcitiT7tfT4MEbawTxSS 2cAzjwPz8zHIQzSYoZXnK+XkkDDWyEU= X-MC-Unique: FHateh3eO7WYwGuF7cBlZA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 08/16] xenParseVif: Refactor parser Date: Tue, 2 Mar 2021 15:49:25 +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.15 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_strsplit to split the string and avoid use of stack'd strings. Signed-off-by: Peter Krempa --- src/libxl/xen_common.c | 136 ++++++++++++++--------------------------- 1 file changed, 46 insertions(+), 90 deletions(-) diff --git a/src/libxl/xen_common.c b/src/libxl/xen_common.c index 781483f496..09c74dcb53 100644 --- a/src/libxl/xen_common.c +++ b/src/libxl/xen_common.c @@ -1141,104 +1141,61 @@ xenParseVif(char *entry, const char *vif_typename) { virDomainNetDefPtr net =3D NULL; virDomainNetDefPtr ret =3D NULL; - char *script =3D NULL; - char model[10]; - char type[10]; - char ip[128]; - char mac[18]; - char bridge[50]; - char vifname[50]; - char rate[50]; - char *key; - - bridge[0] =3D '\0'; - mac[0] =3D '\0'; - ip[0] =3D '\0'; - model[0] =3D '\0'; - type[0] =3D '\0'; - vifname[0] =3D '\0'; - rate[0] =3D '\0'; - - key =3D entry; - while (key) { - char *data; - char *nextkey =3D strchr(key, ','); - - if (!(data =3D strchr(key, '=3D'))) + g_auto(GStrv) keyvals =3D NULL; + GStrv keyval; + g_autofree char *script =3D NULL; + g_autofree char *model =3D NULL; + g_autofree char *type =3D NULL; + g_autofree char *ip =3D NULL; + g_autofree char *mac =3D NULL; + g_autofree char *bridge =3D NULL; + g_autofree char *vifname =3D NULL; + g_autofree char *rate =3D NULL; + + keyvals =3D g_strsplit(entry, ",", 0); + + for (keyval =3D keyvals; keyval && *keyval; keyval++) { + const char *key =3D *keyval; + char *val =3D strchr(key, '=3D'); + + virSkipSpaces(&key); + + if (!val) return NULL; - data++; + + val++; if (STRPREFIX(key, "mac=3D")) { - int len =3D nextkey ? (nextkey - data) : strlen(data); - if (virStrncpy(mac, data, len, sizeof(mac)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("MAC address %s too big for destination"), - data); - return NULL; - } + g_clear_pointer(&mac, g_free); + mac =3D g_strdup(val); } else if (STRPREFIX(key, "bridge=3D")) { - int len =3D nextkey ? (nextkey - data) : strlen(data); - if (virStrncpy(bridge, data, len, sizeof(bridge)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Bridge %s too big for destination"), - data); - return NULL; - } + g_clear_pointer(&bridge, g_free); + bridge =3D g_strdup(val); } else if (STRPREFIX(key, "script=3D")) { - int len =3D nextkey ? (nextkey - data) : strlen(data); - VIR_FREE(script); - script =3D g_strndup(data, len); + g_clear_pointer(&script, g_free); + script =3D g_strdup(val); } else if (STRPREFIX(key, "model=3D")) { - int len =3D nextkey ? (nextkey - data) : strlen(data); - if (virStrncpy(model, data, len, sizeof(model)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Model %s too big for destination"), - data); - return NULL; - } + g_clear_pointer(&model, g_free); + model =3D g_strdup(val); } else 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 too big for destination"), - data); - return NULL; - } + g_clear_pointer(&type, g_free); + type =3D g_strdup(val); } else if (STRPREFIX(key, "vifname=3D")) { - int len =3D nextkey ? (nextkey - data) : strlen(data); - if (virStrncpy(vifname, data, len, sizeof(vifname)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Vifname %s too big for destination"), - data); - return NULL; - } + g_clear_pointer(&vifname, g_free); + vifname =3D g_strdup(val); } else if (STRPREFIX(key, "ip=3D")) { - int len =3D nextkey ? (nextkey - data) : strlen(data); - if (virStrncpy(ip, data, len, sizeof(ip)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("IP %s too big for destination"), data); - return NULL; - } + g_clear_pointer(&ip, g_free); + ip =3D g_strdup(val); } else if (STRPREFIX(key, "rate=3D")) { - int len =3D nextkey ? (nextkey - data) : strlen(data); - if (virStrncpy(rate, data, len, sizeof(rate)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("rate %s too big for destination"), data); - return NULL; - } + g_clear_pointer(&rate, g_free); + rate =3D g_strdup(val); } - - while (nextkey && (nextkey[0] =3D=3D ',' || - nextkey[0] =3D=3D ' ' || - nextkey[0] =3D=3D '\t')) - nextkey++; - key =3D nextkey; } if (!(net =3D virDomainNetDefNew(NULL))) goto cleanup; - if (mac[0]) { + if (mac) { if (virMacAddrParse(mac, &net->mac) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("malformed mac address '%s'"), mac); @@ -1246,18 +1203,18 @@ xenParseVif(char *entry, const char *vif_typename) } } - if (bridge[0] || STREQ_NULLABLE(script, "vif-bridge") || + if (bridge || STREQ_NULLABLE(script, "vif-bridge") || STREQ_NULLABLE(script, "vif-vnic")) { net->type =3D VIR_DOMAIN_NET_TYPE_BRIDGE; } else { net->type =3D VIR_DOMAIN_NET_TYPE_ETHERNET; } - if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_BRIDGE && bridge[0]) { + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_BRIDGE && bridge) { if (xenParseVifBridge(net, bridge) < 0) goto cleanup; } - if (ip[0]) { + if (ip) { char **ip_list =3D g_strsplit(ip, " ", 0); size_t i; @@ -1276,18 +1233,18 @@ xenParseVif(char *entry, const char *vif_typename) if (script && script[0]) net->script =3D g_strdup(script); - if (model[0]) { + if (model) { if (virDomainNetSetModelString(net, model) < 0) goto cleanup; } else { - if (type[0] && STREQ(type, vif_typename)) + if (type && STREQ(type, vif_typename)) net->model =3D VIR_DOMAIN_NET_MODEL_NETFRONT; } - if (vifname[0]) + if (vifname && vifname[0]) net->ifname =3D g_strdup(vifname); - if (rate[0]) { + if (rate) { virNetDevBandwidthPtr bandwidth; unsigned long long kbytes_per_sec; @@ -1304,7 +1261,6 @@ xenParseVif(char *entry, const char *vif_typename) cleanup: virDomainNetDefFree(net); - VIR_FREE(script); return ret; } --=20 2.29.2 From nobody Sat May 4 04:35:24 2024 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=1614696620; cv=none; d=zohomail.com; s=zohoarc; b=SzGUccje2y5mWHs7sFk539fnpT0XCGwfCgqTkzOLUW9tYqva0r2PlqOtb7hIMoahFBIkMR3Vv7NY5p7MV1K7lMjUXt3MDEJdvkEzbw+camazMo9XGlRgjtpDph+h25gQFhzUhwd9Dfx6YjH9jSMbYd0LQotKSpitd1QWCe2HX7c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614696620; 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=6Ui8n/UluthRYsf5u3OpzPlZbnzadN1/D+7eEe6JgJY=; b=iJx47L8xWyaeqnEdIAeZYhXO6vo1pFPqqPrRuZCPGcepLVEzeDoe2fKNoG81T0PzSYcXI2SRAzHYluhcS8dJgz+fB/OWzF9uFzajmECAuZrbr9CY+V0dNQ33Lpa7joNXfMTv+Ai4S7uNPzCn77qETQzwykfbYP4/7vK5JiS1EBE= 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 1614696620358948.4871693529622; Tue, 2 Mar 2021 06:50:20 -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-470-Gga_GUIMMfyXYok136h22w-1; Tue, 02 Mar 2021 09:50:16 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E8E3650753; Tue, 2 Mar 2021 14:50:09 +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 C301068D22; Tue, 2 Mar 2021 14:50:09 +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 871CC58080; Tue, 2 Mar 2021 14:50:09 +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 122Enm8d014506 for ; Tue, 2 Mar 2021 09:49:48 -0500 Received: by smtp.corp.redhat.com (Postfix) id 641835D723; Tue, 2 Mar 2021 14:49:48 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 95EAF5D722 for ; Tue, 2 Mar 2021 14:49:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614696619; 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=6Ui8n/UluthRYsf5u3OpzPlZbnzadN1/D+7eEe6JgJY=; b=SjcA1fwY8mVrh8SGHpeqkgrW+3oYiG8m4PrpCs4UDJEn0TrMafDGgjJbs1brLZ6JBo5Zvl kHQhuyXNGMYP7ISiUnIffoLy8foyBqCCAQWbaLZJft22AF82SN2pZDz7kQU9Sj1m2HhcE7 4X2kcN5IcdYtRaB2rHOpG2O3kfnWabQ= X-MC-Unique: Gga_GUIMMfyXYok136h22w-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 09/16] xenParseSxprSound: Refactor parsing of model list Date: Tue, 2 Mar 2021 15:49:26 +0100 Message-Id: <71d05c6643cc7c532d1a89941bef9800b6e0f7e2.1614696480.git.pkrempa@redhat.com> 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.16 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" Copy the input string so that we don't have to use a static buffer and virStrncpy. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/libxl/xen_common.c | 46 +++++++++++++++++------------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/src/libxl/xen_common.c b/src/libxl/xen_common.c index 09c74dcb53..1c71f69209 100644 --- a/src/libxl/xen_common.c +++ b/src/libxl/xen_common.c @@ -1332,38 +1332,30 @@ xenParseSxprSound(virDomainDefPtr def, def->sounds[def->nsounds++] =3D sound; } } else { - char model[10]; - const char *offset =3D str, *offset2; - - do { - int len; - virDomainSoundDefPtr sound; - offset2 =3D strchr(offset, ','); - if (offset2) - len =3D (offset2 - offset); - else - len =3D strlen(offset); - if (virStrncpy(model, offset, len, sizeof(model)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Sound model %s too big for destination"), - offset); - return -1; - } + g_autofree char *sounds =3D g_strdup(str); + char *sound =3D sounds; + int model; - sound =3D g_new0(virDomainSoundDef, 1); + while (*sound !=3D '\0') { + char *next =3D strchr(sound, ','); + virDomainSoundDefPtr snddef; - if ((sound->model =3D virDomainSoundModelTypeFromString(model)= ) < 0) { - VIR_FREE(sound); - return -1; - } + if (next) + *next =3D '\0'; - if (VIR_APPEND_ELEMENT(def->sounds, def->nsounds, sound) < 0) { - virDomainSoundDefFree(sound); + if ((model =3D virDomainSoundModelTypeFromString(sound)) < 0) return -1; - } - offset =3D offset2 ? offset2 + 1 : NULL; - } while (offset); + snddef =3D g_new0(virDomainSoundDef, 1); + snddef->model =3D model; + + ignore_value(VIR_APPEND_ELEMENT(def->sounds, def->nsounds, snd= def)); + + if (!next) + break; + + sound =3D next + 1; + } } return 0; --=20 2.29.2 From nobody Sat May 4 04:35:24 2024 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 From nobody Sat May 4 04:35:24 2024 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=1614696619; cv=none; d=zohomail.com; s=zohoarc; b=hQlO3q39uOzVvynOCbEdhLzVA3On8fScmj6ld4ZdJbEiFVvg8hZcncEkuutPMMdyUl4AC7TTrI9AiXcLX3SK4X9dkl0s8ig32912zWomMWAbnoHFhUMtaWOATtweXASKI7XmY/a+Q1C+uupMxeCTVZfvnpdJ3OkrbCcsVnE5trM= 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=CpDgj/HcG3+6LVdbnL4UKWH8kuiuxY5DTG5bSZ4Bdu8=; b=grTfO0ZO+sdwDem33YaawbufBrU82wCo06WPJI5ZD+u8XAETmvAySzgMjV2UIZIpsL2gn6LxKkSHKjupCLpLxMN2Ne6Qrzrw47sQ/GL4yP91U+qb7y3CZTlP4zCIGFw5EQjQs0IaRkcEVzsNZqzUFGPnRnTn6AaARmmxu+3neYs= 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 1614696619275947.7813712520093; 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-452-I71v4CYzPGaHkRrlHVaqqA-1; Tue, 02 Mar 2021 09:50:16 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D32D7107ACE8; Tue, 2 Mar 2021 14:50:08 +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 A8A091002388; Tue, 2 Mar 2021 14:50:08 +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 657065807D; Tue, 2 Mar 2021 14:50:08 +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 122EnoD0014526 for ; Tue, 2 Mar 2021 09:49:50 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7793D5D722; Tue, 2 Mar 2021 14:49:50 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id D162C5D766 for ; Tue, 2 Mar 2021 14:49:49 +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=CpDgj/HcG3+6LVdbnL4UKWH8kuiuxY5DTG5bSZ4Bdu8=; b=QHSk7yYkoPbBo+XB4hUsDveBZjqoXS04rUbW51WKp4tAWos/dqHBf4egyMWAfcwaiUutQc JW6X3PwPiWstnMXogvj/NybYgnPcfoa2hV5oNSf7SrZV39zJLB8JHKyZCYClSodP1G8B6L sTrpPoXp9SwjISZJQdjcuiA2l2Vio4U= X-MC-Unique: I71v4CYzPGaHkRrlHVaqqA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 11/16] xenParseXLChannel: Use g_strndup instead of virStrndup Date: Tue, 2 Mar 2021 15:49:28 +0100 Message-Id: <9b3d8f4d8e1dcff0fba333c0c24721e88eb73323.1614696480.git.pkrempa@redhat.com> 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.84 on 10.5.11.22 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" Make the temporary string a autofree-ing pointer and copy the contents. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/libxl/xen_xl.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/libxl/xen_xl.c b/src/libxl/xen_xl.c index 4113be8cd1..9b2a2fe292 100644 --- a/src/libxl/xen_xl.c +++ b/src/libxl/xen_xl.c @@ -1070,7 +1070,7 @@ xenParseXLChannel(virConfPtr conf, virDomainDefPtr de= f) if (list && list->type =3D=3D VIR_CONF_LIST) { list =3D list->list; while (list) { - char type[10]; + g_autofree char *type =3D NULL; char *key; if ((list->type !=3D VIR_CONF_STRING) || (list->str =3D=3D NUL= L)) @@ -1087,11 +1087,8 @@ xenParseXLChannel(virConfPtr conf, virDomainDefPtr d= ef) if (STRPREFIX(key, "connection=3D")) { int len =3D nextkey ? (nextkey - data) : strlen(data); - if (virStrncpy(type, data, len, sizeof(type)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("connection %s too big"), data); - goto skipchannel; - } + g_clear_pointer(&type, g_free); + type =3D g_strndup(data, len); } else if (STRPREFIX(key, "name=3D")) { int len =3D nextkey ? (nextkey - data) : strlen(data); VIR_FREE(name); --=20 2.29.2 From nobody Sat May 4 04:35:24 2024 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 From nobody Sat May 4 04:35:24 2024 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=1614696667; cv=none; d=zohomail.com; s=zohoarc; b=J0k5COk48vjE24T8zBK/wYv2CtvNk1FIkKWekZPHwM9mv945T6XDdeHMlUbPOZ07CjNn1TMevVmB7teZWH83aRSLWIeg9e90odagLcskb8tHVxbx8GwaYfzfpPP4/28lt5/pHydt/kOcZslSqQ14rcpZHv7PG26Qca2+7rBqgHI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614696667; 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=4BHM7Ol3SQKWuqEXvAcYVCwVctU52DO+sxyH9jTlf/M=; b=l68sAf3hGUHMc4HJwb4I2rF/iVJnkddCFaHyVw//wxZoXCAVyxO3VXHQYOfDQrQT3Ldwd4+lvuApEIH62FEcTHl2gKdlAdgxp331SzeHXLBKUo1XaHeSHW0eoYNwk1jVYOo2JMwMNdeEMKkSkPcIWl8sOLx2ZgLUxnlQe4UlYXA= 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 161469666780665.85202459940683; Tue, 2 Mar 2021 06:51:07 -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-132-fCWizUGOOyWdnWx-EU_mMg-1; Tue, 02 Mar 2021 09:50:18 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2D763100CCC8; Tue, 2 Mar 2021 14:50:12 +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 0B66060C13; Tue, 2 Mar 2021 14:50:12 +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 B9D4818089D2; Tue, 2 Mar 2021 14:50:11 +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 122EnqwW014543 for ; Tue, 2 Mar 2021 09:49:52 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8A1295D722; Tue, 2 Mar 2021 14:49:52 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id EA60E5D766 for ; Tue, 2 Mar 2021 14:49:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614696666; 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=4BHM7Ol3SQKWuqEXvAcYVCwVctU52DO+sxyH9jTlf/M=; b=TL8xG5TtYyi6v66lzkDPcoX5sTjeM3dLNLYq/UYFtYLi2W1djdqOCYY0OHraXlHqCQUFu8 Luco+qGtU2OxOgj5VBv93N8lehqHAZdlHvLo3dywm/XYLgIjJeMWE5W54gJhlECfsszaO7 6ptbamtGrCJpD9gphIXFIXbyMOfLjTo= X-MC-Unique: fCWizUGOOyWdnWx-EU_mMg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 13/16] xenParseXLUSB: Rewrite to avoid virStrncpy Date: Tue, 2 Mar 2021 15:49:30 +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.12 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" Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/libxl/xen_xl.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/src/libxl/xen_xl.c b/src/libxl/xen_xl.c index 1bce31a549..29c145851e 100644 --- a/src/libxl/xen_xl.c +++ b/src/libxl/xen_xl.c @@ -960,14 +960,10 @@ xenParseXLUSB(virConfPtr conf, virDomainDefPtr def) if (list && list->type =3D=3D VIR_CONF_LIST) { list =3D list->list; while (list) { - char bus[3]; - char device[3]; char *key; int busNum; int devNum; - bus[0] =3D device[0] =3D '\0'; - if ((list->type !=3D VIR_CONF_STRING) || (list->str =3D=3D NUL= L)) goto skipusb; /* usbdev=3D['hostbus=3D1,hostaddr=3D3'] */ @@ -982,20 +978,16 @@ xenParseXLUSB(virConfPtr conf, virDomainDefPtr def) if (STRPREFIX(key, "hostbus=3D")) { int len =3D nextkey ? (nextkey - data) : strlen(data); - if (virStrncpy(bus, data, len, sizeof(bus)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("bus %s too big for destination"), - data); + g_autofree char *tmp =3D g_strndup(data, len); + + if (virStrToLong_i(tmp, NULL, 16, &busNum) < 0) goto skipusb; - } } else if (STRPREFIX(key, "hostaddr=3D")) { int len =3D nextkey ? (nextkey - data) : strlen(data); - if (virStrncpy(device, data, len, sizeof(device)) < 0)= { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("device %s too big for destinatio= n"), - data); + g_autofree char *tmp =3D g_strndup(data, len); + + if (virStrToLong_i(tmp, NULL, 16, &devNum) < 0) goto skipusb; - } } while (nextkey && (nextkey[0] =3D=3D ',' || @@ -1005,10 +997,6 @@ xenParseXLUSB(virConfPtr conf, virDomainDefPtr def) key =3D nextkey; } - if (virStrToLong_i(bus, NULL, 16, &busNum) < 0) - goto skipusb; - if (virStrToLong_i(device, NULL, 16, &devNum) < 0) - goto skipusb; if (!(hostdev =3D virDomainHostdevDefNew())) return -1; --=20 2.29.2 From nobody Sat May 4 04:35:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1614696664; cv=none; d=zohomail.com; s=zohoarc; b=mMpgOkuKu9mx7gbV9hzPokTwKM/jACv+MvdUJ3oOFiWAQIG4cRtfLCfVsuu5wSFqJWBTsdv5LQH+AeyobzcQ/1QDm40ePapGrpfXj6MTCluHNNpdyHqlUIQIR5pT7SWih4ajjSmzlJb1BiMoEz5DDmUzYr80WL9QP0E6pIjFew4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614696664; 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=qJ9DAgVRq+8j0vt+DK3475UQd5k9H8W3r9gsnBDs2pc=; b=HqCKbM9r4g3fkvNGe7qJvxPL7dqQ0AXLsmRQXRGRzrQ/+SNFzN2gWYhjW9DHjZDyr0ytwB4YAkWPOZaaeHUYyIt8FBZujhM6ogNnc8Lh4YXFzoFb7e8mq9qMk2b1//gDGyD72Gvci+MzokVSjEhqeOsbjsV3v7GJk7Sfl4roLyc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 1614696664440329.4119148869587; Tue, 2 Mar 2021 06:51:04 -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-74-Ev1mLK43MqSDdzzUgiQi9Q-1; Tue, 02 Mar 2021 09:50:22 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6F0A0100CCC4; Tue, 2 Mar 2021 14:50:17 +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 43B4A5D722; Tue, 2 Mar 2021 14:50:17 +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 09B4818077C0; Tue, 2 Mar 2021 14:50:17 +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 122Enr1m014554 for ; Tue, 2 Mar 2021 09:49:53 -0500 Received: by smtp.corp.redhat.com (Postfix) id 9F98A5D766; Tue, 2 Mar 2021 14:49:53 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 01C845D722 for ; Tue, 2 Mar 2021 14:49:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614696663; 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=qJ9DAgVRq+8j0vt+DK3475UQd5k9H8W3r9gsnBDs2pc=; b=BrfqSnQ0zKDvgPK/ICflZGKIz6cBXKmqYQVG3mqCCWJL84GCctjHm04yd5YO1znP4BwH2R GheXSl8/v34Snj/4Xm2y2kP3HszndQ2zxrhMUH3xWnmaXxiSdSbnWdDSDTZZ001yl8bNw2 u/bjigMV/aY+3jKQHlwUem6iTpmOkoM= X-MC-Unique: Ev1mLK43MqSDdzzUgiQi9Q-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 14/16] virNetLibsshAuthenticatePrivkeyCb: Use g_autofree for 'actual_prompt' Date: Tue, 2 Mar 2021 15:49:31 +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.15 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" So that the 'error' label can be removed. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/rpc/virnetlibsshsession.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/rpc/virnetlibsshsession.c b/src/rpc/virnetlibsshsession.c index 8814487557..0fc1f66706 100644 --- a/src/rpc/virnetlibsshsession.c +++ b/src/rpc/virnetlibsshsession.c @@ -406,7 +406,7 @@ virNetLibsshAuthenticatePrivkeyCb(const char *prompt, virNetLibsshSessionPtr sess =3D userdata; virConnectCredential retr_passphrase; int cred_type; - char *actual_prompt =3D NULL; + g_autofree char *actual_prompt =3D NULL; int p; /* request user's key password */ @@ -421,7 +421,7 @@ virNetLibsshAuthenticatePrivkeyCb(const char *prompt, if (cred_type =3D=3D -1) { virReportError(VIR_ERR_LIBSSH, "%s", _("no suitable callback for input of key passphrase= ")); - goto error; + return -1; } actual_prompt =3D g_strndup(prompt, virLengthForPromptString(prompt)); @@ -434,7 +434,7 @@ virNetLibsshAuthenticatePrivkeyCb(const char *prompt, virReportError(VIR_ERR_LIBSSH, "%s", _("failed to retrieve private key passphrase: " "callback has failed")); - goto error; + return -1; } p =3D virStrncpy(buf, retr_passphrase.result, @@ -444,16 +444,10 @@ virNetLibsshAuthenticatePrivkeyCb(const char *prompt, if (p < 0) { virReportError(VIR_ERR_LIBSSH, "%s", _("passphrase is too long for the buffer")); - goto error; + return -1; } - VIR_FREE(actual_prompt); - return 0; - - error: - VIR_FREE(actual_prompt); - return -1; } static int --=20 2.29.2 From nobody Sat May 4 04:35:24 2024 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=1614696629; cv=none; d=zohomail.com; s=zohoarc; b=QLIhq/kAo9kgaptZN/WXFVWaEQGXFJSSDnqGZwKSQFrDScgAygfDCb0Ru3pf/OdHQOSlrTQP4SVATIHGx1HlTa/q78d4+Fm+lg1nDS/7SmuVeWMfEs4OSBV40mVqOKlhF9XzoBT+QXVmsekTkwZgH33MZRyBzM0aROefQteeHqY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614696629; 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=AgKGgDdPtQd+hZzzmg2gRiPFXpEBQmuwxfzS9RPgb8E=; b=BJsb1oXJTKMIV39ED4Rc41GgF51K7T2ciuEJ65l1XR7JQ2qG4kB2ysFfHjJK7n2TIZBJcnGZgU5q5oqiVCbhj4fsqqNSUuBsoSgW91Lo4JccxjMotQF2Xt1tg4yt9AMD7UIa8KUynSiX8OHlck8FdcnzisKMucuiDBm9vvizzww= 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 1614696629766533.6749460890576; Tue, 2 Mar 2021 06:50:29 -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-571-xxwGksXtN_y8VvmqeYICHQ-1; Tue, 02 Mar 2021 09:50:26 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A0B7918BA28A; Tue, 2 Mar 2021 14:50:20 +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 7BC0660C05; Tue, 2 Mar 2021 14:50:20 +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 3A95D58089; Tue, 2 Mar 2021 14:50:20 +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 122Envdp014583 for ; Tue, 2 Mar 2021 09:49:57 -0500 Received: by smtp.corp.redhat.com (Postfix) id BC7305D722; Tue, 2 Mar 2021 14:49:57 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 217EB5D766 for ; Tue, 2 Mar 2021 14:49:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614696628; 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=AgKGgDdPtQd+hZzzmg2gRiPFXpEBQmuwxfzS9RPgb8E=; b=JjQss9mahWOhNhdjtYio07OIhiYMZDCPHOcW9WpDTMBNw87euliusU5QFkXnzvfaS/FJD0 V9RZDnNDzPlYeP942ftRxlpxDMjQcfWmnPnr57xVcKb6pQRIU6ZZL2rd8po34OtpNghOY8 H3BZBH8mHasH750E08F68Io+wm3GnW4= X-MC-Unique: xxwGksXtN_y8VvmqeYICHQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 15/16] virNetLibsshAuthenticatePrivkeyCb: Use virStrcpy instead of virStrncpy Date: Tue, 2 Mar 2021 15:49:32 +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.12 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" We already assume that 'retr_passphrase.result' is a string, thus we can use virStrcpy instead. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/rpc/virnetlibsshsession.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/rpc/virnetlibsshsession.c b/src/rpc/virnetlibsshsession.c index 0fc1f66706..2dc8cc8911 100644 --- a/src/rpc/virnetlibsshsession.c +++ b/src/rpc/virnetlibsshsession.c @@ -437,8 +437,7 @@ virNetLibsshAuthenticatePrivkeyCb(const char *prompt, return -1; } - p =3D virStrncpy(buf, retr_passphrase.result, - retr_passphrase.resultlen, len); + p =3D virStrcpy(buf, retr_passphrase.result, len); virSecureEraseString(retr_passphrase.result); g_free(retr_passphrase.result); if (p < 0) { --=20 2.29.2 From nobody Sat May 4 04:35:24 2024 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=1614696688; cv=none; d=zohomail.com; s=zohoarc; b=fMHWGI8ND7u2aForzS560k9/OsO2FtyOS382NNbLkd7amvIL8q0NNqJMmKtZQznJGFzKTYfIY/X4yf5tK4JU2jdyMJp6ZI6reHr+t9Thfh/f1cr25rerGCZ2DJE1DyPuq7epCjpZf0LnNqfBsOlOlw8k1pzptANXkXZIt7q+8ss= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614696688; 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=S2eMo1TxG6PRDs4G1dGJYqrttNpMZHfdQTU4zghMh0Y=; b=I4NpK8Vo1zb1VYEULbI00iW9aXSFWtlTY9XvjIWRqy5KA85OChg8ErpNSBqflf67Mb/SqjW6EOwSi3biawElArAGR74gOluuSDDuSZr+FUt4OQ3mNxKsysTlrUR/kfFUBzWy3wnSB9uMyhyUnjj5x59H3Lj5F1CBgM2o9CJwmH0= 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 1614696688572972.2981253111203; Tue, 2 Mar 2021 06:51:28 -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-351-OOw8N40lMy6n4g-eHGk-6Q-1; Tue, 02 Mar 2021 09:50:21 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6A27D801983; Tue, 2 Mar 2021 14:50:15 +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 44B095D9E2; Tue, 2 Mar 2021 14:50:15 +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 0928B1800237; Tue, 2 Mar 2021 14:50:15 +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 122EnwrH014589 for ; Tue, 2 Mar 2021 09:49:58 -0500 Received: by smtp.corp.redhat.com (Postfix) id C66EC5D768; Tue, 2 Mar 2021 14:49:58 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 354FB5D722 for ; Tue, 2 Mar 2021 14:49:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614696686; 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=S2eMo1TxG6PRDs4G1dGJYqrttNpMZHfdQTU4zghMh0Y=; b=YFyreTwc2IiDbg4a+ejzg/Z9uqvYykFkfcCIPcSjq9gir5QoY6Vp+fgGD5zSs040TubBbX e/OI3bg587jiTDRCe3N1eEYWbyzniKdiAaeSYEEZT/ZKbXqscZNf0zXEE0il+EvrHx0Ndt vj+6hXViPVwXfuqPwaxlp9Qg7vt8R/Q= X-MC-Unique: OOw8N40lMy6n4g-eHGk-6Q-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 16/16] util: virstring: Remove virStrncpy Date: Tue, 2 Mar 2021 15:49:33 +0100 Message-Id: <8dad823eeae2499263c6cc8e225716a7f23ab41d.1614696480.git.pkrempa@redhat.com> 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.14 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" The function is now unused and motivated users to write crazy parsers which were hard to understand, had pointless error paths just to avoid few memory allocations. Remove the function as we're fine with g_strndup and virStrcpy. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- docs/coding-style.rst | 13 ------------ src/libvirt_private.syms | 1 - src/util/virstring.c | 44 ---------------------------------------- src/util/virstring.h | 2 -- 4 files changed, 60 deletions(-) diff --git a/docs/coding-style.rst b/docs/coding-style.rst index 55dfa196a2..c43d20c7b2 100644 --- a/docs/coding-style.rst +++ b/docs/coding-style.rst @@ -714,19 +714,6 @@ does **not** guarantee a NULL-terminated buffer, which= makes it extremely dangerous to use. Instead, use one of the replacement functions provided by libvirt: -:: - - virStrncpy(char *dest, const char *src, size_t n, size_t destbytes) - -The first two arguments have the same meaning as for strncpy, -namely the destination and source of the copy operation. Unlike -strncpy, the function will always copy exactly the number of bytes -requested and make sure the destination is NULL-terminated, as the -source is required to be; sanity checks are performed to ensure -the size of the destination, as specified by the last argument, is -sufficient for the operation to succeed. On success, 0 is -returned; on failure, a value <0 is returned instead. - :: virStrcpy(char *dest, const char *src, size_t destbytes) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 2a3bbdc577..eb121032d5 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3264,7 +3264,6 @@ virStringStripIPv6Brackets; virStringStripSuffix; virStringToUpper; virStringTrimOptionalNewline; -virStrncpy; virStrToDouble; virStrToLong_i; virStrToLong_l; diff --git a/src/util/virstring.c b/src/util/virstring.c index a35cd8ba76..1d6141b5c1 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -452,50 +452,6 @@ virDoubleToStr(char **strp, double number) } -/** - * virStrncpy: - * - * @dest: destination buffer - * @src: source buffer - * @n: number of bytes to copy - * @destbytes: number of bytes the destination can accommodate - * - * Copies the first @n bytes of @src to @dest. - * - * @src must be NULL-terminated; if successful, @dest is guaranteed to - * be NULL-terminated as well. - * - * @n must be a reasonable value, that is, it must not exceed either - * the length of @src or the size of @dest. For the latter constraint, - * the fact that @dest needs to accommodate a NULL byte in addition to - * the bytes copied from @src must be taken into account. - * - * If you want to copy *all* of @src to @dest, use virStrcpy() or - * virStrcpyStatic() instead. - * - * Returns: 0 on success, <0 on failure. - */ -int -virStrncpy(char *dest, const char *src, size_t n, size_t destbytes) -{ - size_t src_len =3D strlen(src); - - /* As a special case, -1 means "copy the entire string". - * - * This is to avoid calling strlen() twice, once in the virStrcpy() - * wrapper and once here for bound checking purposes. */ - if (n =3D=3D -1) - n =3D src_len; - - if (n > src_len || n > (destbytes - 1)) - return -1; - - memcpy(dest, src, n); - dest[n] =3D '\0'; - - return 0; -} - /** * virStrcpy: * diff --git a/src/util/virstring.h b/src/util/virstring.h index da1fe86ffc..e688495574 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -97,8 +97,6 @@ void virSkipSpacesBackwards(const char *str, char **endp) bool virStringIsEmpty(const char *str); -int virStrncpy(char *dest, const char *src, size_t n, size_t destbytes) - G_GNUC_WARN_UNUSED_RESULT; int virStrcpy(char *dest, const char *src, size_t destbytes); #define virStrcpyStatic(dest, src) virStrcpy((dest), (src), sizeof(dest)) --=20 2.29.2