From nobody Fri Dec 12 12:53:26 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1764251693; cv=none; d=zohomail.com; s=zohoarc; b=eSmI0mDIaF8EHS07ISeq1Lpmz1kFuDDFaDOD+kldvsy/MgRe4L4WVPoqEs1Uw5PGK68WBwgBYOHUj2w3Q/zd/+h9dMF6xoAylYgiJOSaMoDpHBt+ZUlG+k9ebdDC/Vvq08APkt9pvcsXHQWuhjtCv73rp67CeyUarzb6mIdlpRM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1764251693; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=7N+lgbYhK6D9yZ/dgBYENd/IErTI5gm4Y6/bnGKqGsw=; b=g0/LzNk9azRaLIKbNlL3lnGLgQsnK/TgFjOlG1SsaJERp7Lag++RyEP2yMX3ALyta1Zrzu5612X3zQYnrAHMoooCxSNpf9ZgbflP3H/f8ylkiKlNchhapPUBKrvnhBkIrWufFylXb8z/i230aFzGOKW+/iZnezUU1ofYGiK/FrI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 176425169346964.1128293147533; Thu, 27 Nov 2025 05:54:53 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id C6CF244C31; Thu, 27 Nov 2025 08:54:52 -0500 (EST) Received: from [172.19.199.74] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 5E9BB44BC6; Thu, 27 Nov 2025 08:53:06 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id 3C20E41A87; Thu, 27 Nov 2025 08:52:36 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 82CE244B4A for ; Thu, 27 Nov 2025 08:51:10 -0500 (EST) Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-399-HUWWcF6kMtyQIUaLMKITHQ-1; Thu, 27 Nov 2025 08:51:08 -0500 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EBF961800359 for ; Thu, 27 Nov 2025 13:51:07 +0000 (UTC) Received: from moe (unknown [10.43.3.236]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 40D361800451 for ; Thu, 27 Nov 2025 13:51:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1764251470; h=from:from: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; bh=7N+lgbYhK6D9yZ/dgBYENd/IErTI5gm4Y6/bnGKqGsw=; b=MEessRjSaxHSbjz2q/iYh/yC/V1fgTjwhRMtDNL0xFe1roS5OeVQCUc73Ii4ofWRUqJrNb rw6nQimnh1CAoECi0mAIY4fHdioiCJor64gAve3jFx50JUDh15gTxjGJWrEjqO6cOFOGcR M6+fIgfwcwpMPownLNMafTEO/vjaiQ0= X-MC-Unique: HUWWcF6kMtyQIUaLMKITHQ-1 X-Mimecast-MFC-AGG-ID: HUWWcF6kMtyQIUaLMKITHQ_1764251468 To: devel@lists.libvirt.org Subject: [PATCH 1/8] vircommand: Update documentation to virCommandSetDryRun() Date: Thu, 27 Nov 2025 14:50:56 +0100 Message-ID: <0f169af8f95ee49b619c45e1ede0020821ebee26.1764251323.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: -6JUSummU-MtQLbqTvJBhchMCJjCSRXMqkFDU28bKKc_1764251468 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: TRXGRDZQKZXXADPDXMFCUPDVHBMYT6KI X-Message-ID-Hash: TRXGRDZQKZXXADPDXMFCUPDVHBMYT6KI X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1764251693816019200 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik Throughout years, virCommandSetDryRun() has gained more functionality and arguments. But: 1) not all arguments are covered in documentation, 2) the example wouldn't even compile. Expand the documentation to reflect current behaviour. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko Tested-by: Jaroslav Suchanek --- src/util/vircommand.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/util/vircommand.c b/src/util/vircommand.c index d9e4c0181f..1390c80a32 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -3184,6 +3184,7 @@ virCommandDryRunTokenFree(virCommandDryRunToken *tok) * @bufArgLinebreaks: add linebreaks after command and every argument or a= rgument pair * @bufCommandStripPath: strip leading paths of command * @callback: callback to process input/output/args + * @opaque: data blob to pass to @callback * * Sometimes it's desired to not actually run given command, but * see its string representation without having to change the @@ -3200,13 +3201,14 @@ virCommandDryRunTokenFree(virCommandDryRunToken *to= k) * The strings stored in @buf are escaped for a shell and * separated by a newline. For example: * - * virBuffer buffer =3D VIR_BUFFER_INITIALIZER; - * virCommandSetDryRun(&buffer); - * + * g_auto(virBuffer) cmdbuf =3D VIR_BUFFER_INITIALIZER; + * g_autoptr(virCommandDryRunToken) dryRunToken =3D virCommandDryRunTokenN= ew(); * virCommand *echocmd =3D virCommandNewArgList("/bin/echo", "Hello world"= , NULL); + * + * virCommandSetDryRun(dryRunToken, &cmdbuf, false, false, NULL, NULL); * virCommandRun(echocmd, NULL); * - * After this, the @buffer should contain: + * After this, the @cmdbuf should contain: * * /bin/echo 'Hello world'\n * --=20 2.51.2 From nobody Fri Dec 12 12:53:26 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1764251989; cv=none; d=zohomail.com; s=zohoarc; b=jtqFWWfWuAbrvhVjM2iTlT32sxhIzw0IIiWLcBWOyn4DTBV+HOUikd+yCpFMkjtVzegc68kMFGrGQEVQluZMh8ybLyrU313/3tPi2ipwkxOQssVCVYjzT8in6R64YdIuMRHO1fotmtxRIxB3ng0spwQkCL+P1kYJMAWunYCq0u0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1764251989; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=NVPft1uBDxOYYtrO8a6RbDmMpcTVzR2eHFqE5VgoPy4=; b=Q4nAxnhwVYzjvWqQlNc+uW14CmfKDlOiKjjxQF32OID7bFjl853/gtV4vAsvRShlF308ylyGVgO4UEsVFczpixWYQqKwJtok1y+PuoTiDWwOhOMuJzxJRiUOUBt7BDwNQkuV6oHesU9rxBwTB+hdi82I9DWcW6GQRXt8RXZWz6A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1764251989904758.5312414700727; Thu, 27 Nov 2025 05:59:49 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id EB3A444B9C; Thu, 27 Nov 2025 08:59:44 -0500 (EST) Received: from [172.19.199.74] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 630BF44CEE; Thu, 27 Nov 2025 08:54:21 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id 3C77D418FA; Thu, 27 Nov 2025 08:52:38 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 6437244B18 for ; Thu, 27 Nov 2025 08:51:11 -0500 (EST) Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-250-7xBhDOGrOFOO8hy60au-Xw-1; Thu, 27 Nov 2025 08:51:09 -0500 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 15E591800372 for ; Thu, 27 Nov 2025 13:51:09 +0000 (UTC) Received: from moe (unknown [10.43.3.236]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 60B071800451 for ; Thu, 27 Nov 2025 13:51:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1764251471; h=from:from: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; bh=NVPft1uBDxOYYtrO8a6RbDmMpcTVzR2eHFqE5VgoPy4=; b=JhvVvZ6d1bFg76a+Y5cfaRKZQU2LqhdWwtN5ncAVQR21+/VJbZVOcGysaYaBqX7IPDCrLV 6MWSC2gHIrUGG9vIpQTYwEEObxaZszq0x4m0IOmPXsG4Ics7JWqkKW9nok3eEkDJW/PHpq YnB4ZV38OajtjFg4y2v7QtEljdnI7yo= X-MC-Unique: 7xBhDOGrOFOO8hy60au-Xw-1 X-Mimecast-MFC-AGG-ID: 7xBhDOGrOFOO8hy60au-Xw_1764251469 To: devel@lists.libvirt.org Subject: [PATCH 2/8] virstringtest: Introduce a test for virSkipSpacesBackwards() Date: Thu, 27 Nov 2025 14:50:57 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: G_4GBBS1HMqc1TuIX6YhWldi8QAnUbN2Lps7x_JsjAI_1764251469 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 53A6XEL5X7JBIDQRHZRZH222NKFZKLTR X-Message-ID-Hash: 53A6XEL5X7JBIDQRHZRZH222NKFZKLTR X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1764251991971019200 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik The signature and implementation of virSkipSpacesBackwards() is soon about to change. Introduce a test case to make sure its behaviour stays the same. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko Tested-by: Jaroslav Suchanek --- tests/virstringtest.c | 48 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/virstringtest.c b/tests/virstringtest.c index f4976890db..a9c8e621ce 100644 --- a/tests/virstringtest.c +++ b/tests/virstringtest.c @@ -111,6 +111,51 @@ testStringSortCompare(const void *opaque G_GNUC_UNUSED) } =20 =20 +#define TEST_STR "This is a static string with spaces" +#define TEST_SPACES " " + +static int +testSkipSpacesBackwards(const void *opaque G_GNUC_UNUSED) +{ + const char *str =3D TEST_STR TEST_SPACES; + char *eol =3D NULL; + + virSkipSpacesBackwards(str, &eol); + + if (STRNEQ(str, TEST_STR TEST_SPACES)) { + fprintf(stderr, "expected '" TEST_STR TEST_SPACES "' got '%s'\n", = str); + return -1; + } + + while (g_ascii_isspace(*eol)) + eol++; + + if (*eol !=3D '\0') { + fprintf(stderr, "expected empty string, got '%s'\n", eol); + return -1; + } + + eol =3D (char *)str + strlen(TEST_STR); + + virSkipSpacesBackwards(str, &eol); + + if (STRNEQ(str, TEST_STR TEST_SPACES)) { + fprintf(stderr, "expected '" TEST_STR TEST_SPACES "' got '%s'\n", = str); + return -1; + } + + if (STRNEQ(eol, TEST_SPACES)) { + fprintf(stderr, "expected empty string, got '%s'\n", eol); + return -1; + } + + return 0; +} + +#undef TEST_SPACES +#undef TEST_STR + + struct stringSearchData { const char *str; const char *regexp; @@ -463,6 +508,9 @@ mymain(void) if (virTestRun("virStringSortCompare", testStringSortCompare, NULL) < = 0) ret =3D -1; =20 + if (virTestRun("virSkipSpacesBackwards", testSkipSpacesBackwards, NULL= ) < 0) + ret =3D -1; + #define TEST_SEARCH(s, r, x, n, m, e) \ do { \ struct stringSearchData data =3D { \ --=20 2.51.2 From nobody Fri Dec 12 12:53:26 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1764251791; cv=none; d=zohomail.com; s=zohoarc; b=RxqGFR0NdojvQdoVK+dVFDqTfP+cNrFpbmIc3lR1zVGAL3Wfu2TNeHL4+2I6UBL82SB/Ck7NEyCmN9OREOrAJnh4j2rvMcJlLl+ixbP7mYexQzpazAdn6lA/gTBvQ+7bWo1I2BG6ouHGaad+bfPrK6dPpXVTyzXa1wtGPEVNgcc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1764251791; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=q/LB6VVnXcT9fXvU62jz2G7F0pheu5KnLb63MLpj/98=; b=AQ1/a6NLwjNOJWDjGVyv/c4p+OEDiioM2c22t47vGb5IkPbdvvUgYKCzcOZAI01TLoBJbW3NwfgeonNtR4IUqHlWUytR4OPUR7+TG01Le+uz2D0If9OrqqzIdN9JTKPs2U+FZK4gzPYg1M7W5VdYtXNC8ZWOQ6tyPOfC/9OUFGY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1764251791650147.39373284822648; Thu, 27 Nov 2025 05:56:31 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id D70B344C08; Thu, 27 Nov 2025 08:56:30 -0500 (EST) Received: from [172.19.199.74] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id F0C0E3F9AC; Thu, 27 Nov 2025 08:53:24 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id E9E1C41E4A; Thu, 27 Nov 2025 08:52:36 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id C830744C12 for ; Thu, 27 Nov 2025 08:51:12 -0500 (EST) Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-66-6FjuLv4pNcSKx7lbi5lVvA-1; Thu, 27 Nov 2025 08:51:11 -0500 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 36867195605B for ; Thu, 27 Nov 2025 13:51:10 +0000 (UTC) Received: from moe (unknown [10.43.3.236]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 80A601800451 for ; Thu, 27 Nov 2025 13:51:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1764251472; h=from:from: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; bh=q/LB6VVnXcT9fXvU62jz2G7F0pheu5KnLb63MLpj/98=; b=J4ZfiO8PHIiVFvIJhQlh5twRk3jcTb62VxPoPPlPXzLxiGuArwbaDeOItrtGfkBHFXvxyK lr33dsESny5W0bmduF3Enh0N5gxd6AMu9Sk43ahyhA4xN6/6P27cJUboeAHxdWabHOu2Pr 6yI2FwuKyL1/SiK6ihLGmSTwUVNFUbo= X-MC-Unique: 6FjuLv4pNcSKx7lbi5lVvA-1 X-Mimecast-MFC-AGG-ID: 6FjuLv4pNcSKx7lbi5lVvA_1764251470 To: devel@lists.libvirt.org Subject: [PATCH 3/8] virfirewalltest: Introduce testIPtablesSetupPrivateChains() Date: Thu, 27 Nov 2025 14:50:58 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: f6lnwIxVBg2EXXeBoUb9QZE3MkLZgnhVt_OuMfjLfhk_1764251470 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: NZDTEEQ5VYX64TG2RFETP45GJFUT2LC7 X-Message-ID-Hash: NZDTEEQ5VYX64TG2RFETP45GJFUT2LC7 X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1764251792627019200 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik When the network driver starts up it may inject some firewall rules (e.g. for a network with NAT). So far, this scenario wasn't covered in our test suite. The reason for adding this test is twofold: the fist, check we add correct rules, the second is to cover iptablesPrivateChainCreate() as its implementation is soon to be changed. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko Tested-by: Jaroslav Suchanek --- src/network/meson.build | 1 + tests/meson.build | 9 +++- tests/virfirewalltest.c | 111 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 120 insertions(+), 1 deletion(-) diff --git a/src/network/meson.build b/src/network/meson.build index 51bbf7063d..7a98974852 100644 --- a/src/network/meson.build +++ b/src/network/meson.build @@ -10,6 +10,7 @@ if host_machine.system() =3D=3D 'freebsd' network_driver_sources +=3D 'network_pf.c' endif =20 +network_inc_dir =3D include_directories('.') driver_source_files +=3D files(network_driver_sources) stateful_driver_source_files +=3D files(network_driver_sources) =20 diff --git a/tests/meson.build b/tests/meson.build index bb6ee6b4ee..1f73d6c029 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -259,6 +259,13 @@ if conf.has('WITH_QEMU') domaincapstest_link_whole +=3D [ test_utils_qemu_lib ] endif =20 +virfirewalltest_include =3D [] +virfirewalltest_link_with =3D [] +if conf.has('WITH_NETWORK') + virfirewalltest_include +=3D [ network_inc_dir ] + virfirewalltest_link_with +=3D [ network_driver_impl ] +endif + tests +=3D [ { 'name': 'commandtest' }, { 'name': 'cputest', 'link_with': cputest_link_with, 'link_whole': cpute= st_link_whole }, @@ -286,7 +293,7 @@ tests +=3D [ { 'name': 'virerrortest' }, { 'name': 'virfilecachetest' }, { 'name': 'virfiletest' }, - { 'name': 'virfirewalltest' }, + { 'name': 'virfirewalltest', 'include': virfirewalltest_include, 'link_w= ith': virfirewalltest_link_with }, { 'name': 'virhostcputest', 'link_whole': [ test_file_wrapper_lib ] }, { 'name': 'virhostdevtest' }, { 'name': 'viridentitytest' }, diff --git a/tests/virfirewalltest.c b/tests/virfirewalltest.c index 38726dcc7a..942eba90d7 100644 --- a/tests/virfirewalltest.c +++ b/tests/virfirewalltest.c @@ -26,6 +26,9 @@ =20 # include "virbuffer.h" # include "virfirewall.h" +# if WITH_NETWORK +# include "network_iptables.h" +# endif =20 # define LIBVIRT_VIRCOMMANDPRIV_H_ALLOW # include "vircommandpriv.h" @@ -763,6 +766,113 @@ testFirewallQuery(const void *opaque G_GNUC_UNUSED) } =20 =20 +static void G_GNUC_UNUSED +testIPtablesSetupPrivateChainsHook(const char *const *args, + const char *const *env G_GNUC_UNUSED, + const char *input G_GNUC_UNUSED, + char **output, + char **error, + int *status, + void *opaque G_GNUC_UNUSED) +{ + if (STREQ_NULLABLE(*args, "iptables") && + STREQ_NULLABLE(*(args + 1), "-w") && + STREQ_NULLABLE(*(args + 2), "--table") && + STREQ_NULLABLE(*(args + 3), "filter") && + STREQ_NULLABLE(*(args + 4), "--list-rules")) { + *output =3D g_strdup("-P INPUT ACCEPT\n" + "-P FORWARD ACCEPT\n" + "-P OUTPUT ACCEPT\n" + ); + *error =3D NULL; + *status =3D EXIT_SUCCESS; + return; + } + + if (STREQ_NULLABLE(*args, "iptables") && + STREQ_NULLABLE(*(args + 1), "-w") && + STREQ_NULLABLE(*(args + 2), "--table") && + STREQ_NULLABLE(*(args + 3), "nat") && + STREQ_NULLABLE(*(args + 4), "--list-rules")) { + *output =3D g_strdup("-P PREROUTING ACCEPT\n" + "-P INPUT ACCEPT\n" + "-P OUTPUT ACCEPT\n" + "-P POSTROUTING ACCEPT\n"); + *error =3D NULL; + *status =3D EXIT_SUCCESS; + return; + } + + /* Intentionally steering away from empty rules above. This is how the + * table looks AFTER we've injected our rules. The idea is to cover mo= re + * lines, esp. in iptablesPrivateChainCreate(). */ + if (STREQ_NULLABLE(*args, "iptables") && + STREQ_NULLABLE(*(args + 1), "-w") && + STREQ_NULLABLE(*(args + 2), "--table") && + STREQ_NULLABLE(*(args + 3), "mangle") && + STREQ_NULLABLE(*(args + 4), "--list-rules")) { + *output =3D g_strdup("-P PREROUTING ACCEPT\n" + "-P INPUT ACCEPT\n" + "-P FORWARD ACCEPT\n" + "-P OUTPUT ACCEPT\n" + "-P POSTROUTING ACCEPT\n" + "-N LIBVIRT_PRT\n" + "-A POSTROUTING -j LIBVIRT_PRT\n" + "-A LIBVIRT_PRT -o virbr0 -p udp -m udp --dport= 68 -j CHECKSUM --checksum-fill\n"); + *error =3D NULL; + *status =3D EXIT_SUCCESS; + return; + } + + *output =3D NULL; + *error =3D NULL; + *status =3D EXIT_SUCCESS; +} + + +static int +testIPtablesSetupPrivateChains(const void *opaque G_GNUC_UNUSED) +{ +# if WITH_NETWORK + g_auto(virBuffer) cmdbuf =3D VIR_BUFFER_INITIALIZER; + g_autoptr(virCommandDryRunToken) dryRunToken =3D virCommandDryRunToken= New(); + const char *actual; + const char *expected =3D + IPTABLES " -w --table filter --list-rules\n" + IPTABLES " -w --table nat --list-rules\n" + IPTABLES " -w --table mangle --list-rules\n" + IPTABLES " -w --table filter --new-chain LIBVIRT_INP\n" + IPTABLES " -w --table filter --insert INPUT --jump LIBVIRT_INP\n" + IPTABLES " -w --table filter --new-chain LIBVIRT_OUT\n" + IPTABLES " -w --table filter --insert OUTPUT --jump LIBVIRT_OUT\n" + IPTABLES " -w --table filter --new-chain LIBVIRT_FWO\n" + IPTABLES " -w --table filter --insert FORWARD --jump LIBVIRT_FWO\n" + IPTABLES " -w --table filter --new-chain LIBVIRT_FWI\n" + IPTABLES " -w --table filter --insert FORWARD --jump LIBVIRT_FWI\n" + IPTABLES " -w --table filter --new-chain LIBVIRT_FWX\n" + IPTABLES " -w --table filter --insert FORWARD --jump LIBVIRT_FWX\n" + IPTABLES " -w --table nat --new-chain LIBVIRT_PRT\n" + IPTABLES " -w --table nat --insert POSTROUTING --jump LIBVIRT_PRT\= n"; + + virCommandSetDryRun(dryRunToken, &cmdbuf, false, false, testIPtablesSe= tupPrivateChainsHook, NULL); + + if (iptablesSetupPrivateChains(VIR_FIREWALL_LAYER_IPV4) < 0) + return -1; + + actual =3D virBufferCurrentContent(&cmdbuf); + + if (virTestCompareToString(expected, actual) < 0) { + fprintf(stderr, "Unexpected command execution\n"); + return -1; + } + + return 0; +# else + return EXIT_AM_SKIP; +# endif +} + + static int mymain(void) { @@ -784,6 +894,7 @@ mymain(void) RUN_TEST("many rollback", testFirewallManyRollback); RUN_TEST("chained rollback", testFirewallChainedRollback); RUN_TEST("query transaction", testFirewallQuery); + RUN_TEST("setup private chains", testIPtablesSetupPrivateChains); =20 return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } --=20 2.51.2 From nobody Fri Dec 12 12:53:26 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1764251879; cv=none; d=zohomail.com; s=zohoarc; b=ITsGLZkKRZjyCW9W++HZqhxuE1+kr7KteUYZHA8DIdWuVK0JR+RXz8t7Td8vYRsx6tMVttTvW8ebcGE2ZV+bC3o2dE8YsxxK4xvBLr5u0GlE0O18S1Er3UTUi4RashSjhIL1b1mNDFoIllIUjn74Egg0x56WGRSFUJjS8SG6LRA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1764251879; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=8xV1P9eiGzYk+E3aX+KjdoSss6Qa6P80k2Vq2mM34YI=; b=NoaZLf2LJ+OwibqqIOBp3tq4EmQCMCmrluCN5gIvwrGQUa02rdJ0ZoYFz3LMkGuJjMnzhQ8I9/zmb69UJylcAn7Fps6YnySvruC4O+0KiFlo8Q3TBrXyogZJsM0XmyofeACowaWp03gWkOMNIJTnn9i7/Vh/ovKLIVPbnYjJ4P4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1764251879017307.1743718668922; Thu, 27 Nov 2025 05:57:59 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id 78CAD41AA5; Thu, 27 Nov 2025 08:57:58 -0500 (EST) Received: from [172.19.199.74] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 1834044BE1; Thu, 27 Nov 2025 08:53:36 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id 570CF4192A; Thu, 27 Nov 2025 08:52:37 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id DD78644C1F for ; Thu, 27 Nov 2025 08:51:13 -0500 (EST) Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-211-1QOhcDzPOtmNJNkwdQQydQ-1; Thu, 27 Nov 2025 08:51:12 -0500 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 57E9F18001D1 for ; Thu, 27 Nov 2025 13:51:11 +0000 (UTC) Received: from moe (unknown [10.43.3.236]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A08911800451 for ; Thu, 27 Nov 2025 13:51:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1764251473; h=from:from: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; bh=8xV1P9eiGzYk+E3aX+KjdoSss6Qa6P80k2Vq2mM34YI=; b=ACSOKhMDpOV9/+OobaFKgFjSwRmrg/WekqdcIiccfq4NZoy/5RArcCThu6u9s5kfVI9Lvk rbeYt6DgNxJBSAck1MxRVTIn0c9DxVWpk4vQbxxwfLardtezEPPInVSGPhscmuEAefg3qr G2XnDIsL+FDzW80N3ZeIcI5AfxieACo= X-MC-Unique: 1QOhcDzPOtmNJNkwdQQydQ-1 X-Mimecast-MFC-AGG-ID: 1QOhcDzPOtmNJNkwdQQydQ_1764251471 To: devel@lists.libvirt.org Subject: [PATCH 4/8] virSkipSpacesBackwards: Turn @endp into const Date: Thu, 27 Nov 2025 14:50:59 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: bgRWGT2zvOyUku_TcBWMVzHl3xPOEYmaI8nRA2A6qco_1764251471 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: GMYPEZ6SLVBMRRTAC4LPALABJABXDQ4P X-Message-ID-Hash: GMYPEZ6SLVBMRRTAC4LPALABJABXDQ4P X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1764251879557019200 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik The aim of virSkipSpacesBackwards() is find the first space trailing character in given string, For instance, if the input is "Something whitespacey ", then the output should be pointing to the very first space after "y". Problem here is that the input string is constant, but the returned pointer is non-constant. This is confusing, a caller shouldn't be able to modify the string, since the input was a constant string. Therefore, make the function return a const pointer too. Under the hood the function used virTrimSpaces() which under some circumstances could modify the input string. A trick was used to hide this fact away, but to be double sure rewrite the function's body. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko Tested-by: Jaroslav Suchanek --- src/util/virstring.c | 20 +++++++++++++------- src/util/virstring.h | 2 +- src/util/virsysinfo.c | 14 +++++++------- tests/virstringtest.c | 2 +- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/util/virstring.c b/src/util/virstring.c index 7249ab4e7c..e001d76bf1 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -484,17 +484,23 @@ virTrimSpaces(char *str, char **endp) * but spaces. */ void -virSkipSpacesBackwards(const char *str, char **endp) +virSkipSpacesBackwards(const char *str, + const char **endp) { - /* Casting away const is safe, since virTrimSpaces does not - * modify string with this particular usage. */ - char *s =3D (char*) str; + const char *end; =20 if (!*endp) - *endp =3D s + strlen(s); - virTrimSpaces(s, endp); - if (s =3D=3D *endp) + end =3D str + strlen(str); + else + end =3D *endp; + + while (end > str && g_ascii_isspace(end[-1])) + end--; + + if (str =3D=3D end) *endp =3D NULL; + else + *endp =3D end; } =20 /** diff --git a/src/util/virstring.h b/src/util/virstring.h index 3d880faf0c..8c2208ece8 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -75,7 +75,7 @@ void virSkipSpaces(const char **str) ATTRIBUTE_NONNULL(1); void virSkipSpacesAndBackslash(const char **str) ATTRIBUTE_NONNULL(1); void virSkipToDigit(const char **str) ATTRIBUTE_NONNULL(1); void virTrimSpaces(char *str, char **endp) ATTRIBUTE_NONNULL(1); -void virSkipSpacesBackwards(const char *str, char **endp) +void virSkipSpacesBackwards(const char *str, const char **endp) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); =20 bool virStringIsEmpty(const char *str); diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c index 0f12a8964f..c017ad34b7 100644 --- a/src/util/virsysinfo.c +++ b/src/util/virsysinfo.c @@ -625,7 +625,7 @@ virSysinfoParseBIOS(const char *base, virSysinfoBIOSDef= **bios) { int ret =3D -1; const char *cur; - char *eol =3D NULL; + const char *eol =3D NULL; virSysinfoBIOSDef *def; =20 if ((cur =3D strstr(base, "BIOS Information")) =3D=3D NULL) @@ -679,7 +679,7 @@ virSysinfoParseX86System(const char *base, virSysinfoSy= stemDef **sysdef) { int ret =3D -1; const char *cur; - char *eol =3D NULL; + const char *eol =3D NULL; virSysinfoSystemDef *def; =20 if ((cur =3D strstr(base, "System Information")) =3D=3D NULL) @@ -755,7 +755,7 @@ virSysinfoParseX86BaseBoard(const char *base, size_t *nbaseBoard) { const char *cur; - char *eol =3D NULL; + const char *eol =3D NULL; virSysinfoBaseBoardDef *boards =3D NULL; size_t nboards =3D 0; =20 @@ -832,7 +832,7 @@ virSysinfoParseX86Chassis(const char *base, { int ret =3D -1; const char *cur; - char *eol =3D NULL; + const char *eol =3D NULL; virSysinfoChassisDef *def; =20 if ((cur =3D strstr(base, "Chassis Information")) =3D=3D NULL) @@ -942,7 +942,7 @@ virSysinfoParseOEMStrings(const char *base, while ((cur =3D strstr(cur, "String "))) { char *collon =3D NULL; unsigned int idx =3D 0; - char *eol; + const char *eol; =20 cur +=3D 7; =20 @@ -1005,7 +1005,7 @@ static void virSysinfoParseX86Processor(const char *base, virSysinfoDef *ret) { const char *cur, *tmp_base; - char *eol; + const char *eol; virSysinfoProcessorDef *processor; =20 while ((tmp_base =3D strstr(base, "Processor Information")) !=3D NULL)= { @@ -1103,7 +1103,7 @@ static void virSysinfoParseX86Memory(const char *base, virSysinfoDef *ret) { const char *cur, *tmp_base; - char *eol; + const char *eol; virSysinfoMemoryDef *memory; =20 while ((tmp_base =3D strstr(base, "Memory Device")) !=3D NULL) { diff --git a/tests/virstringtest.c b/tests/virstringtest.c index a9c8e621ce..0792155cc3 100644 --- a/tests/virstringtest.c +++ b/tests/virstringtest.c @@ -118,7 +118,7 @@ static int testSkipSpacesBackwards(const void *opaque G_GNUC_UNUSED) { const char *str =3D TEST_STR TEST_SPACES; - char *eol =3D NULL; + const char *eol =3D NULL; =20 virSkipSpacesBackwards(str, &eol); =20 --=20 2.51.2 From nobody Fri Dec 12 12:53:26 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1764251924; cv=none; d=zohomail.com; s=zohoarc; b=IonT0af5VKACsBKwaUAdkDn019opSKPHx/xQMFZ5XUpH4F8IZIthyp6ZegU/rvwZNlvrtnvUuQp+406VpizPvQTGLX7LzNlgqDmveUD4AWfjtlXGhhY9NQBK+gO4bekTnsP/q9jQOe0/qbr6APPlXOyiC9BZwINbMB+xoNaIsBs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1764251924; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=Bcn3fbt8ukUAPNr8SqrQtTJydOFjD5pH80YVeMWKCUc=; b=jbgel9FYHEYLjRidjC6+sGBnKEIssxpkLDtro1QEg11cW3QWPTocOp7chFgtp5MylLplQdEBERqQBLEor2uL0R7/slRWCiuoQajeFc/viMqDCgHhIRg4rjX8dJGjHLF4AdG2zWYcyYzqi9P/THhfitSpa6dj5TG2aSBkEN2KGv8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1764251924674755.7181807195667; Thu, 27 Nov 2025 05:58:44 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id 101C844B37; Thu, 27 Nov 2025 08:58:43 -0500 (EST) Received: from [172.19.199.74] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 5E6F4446AC; Thu, 27 Nov 2025 08:54:01 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id 826F8418CA; Thu, 27 Nov 2025 08:52:37 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id F076E44C22 for ; Thu, 27 Nov 2025 08:51:14 -0500 (EST) Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-215-mfgaHG-pN3uVmRoftWLDuQ-1; Thu, 27 Nov 2025 08:51:13 -0500 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 76114180034F for ; Thu, 27 Nov 2025 13:51:12 +0000 (UTC) Received: from moe (unknown [10.43.3.236]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C127118004A3 for ; Thu, 27 Nov 2025 13:51:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1764251474; h=from:from: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; bh=Bcn3fbt8ukUAPNr8SqrQtTJydOFjD5pH80YVeMWKCUc=; b=M66BRk6Gvga4adA1KDgsdblDv3qOZamZfsdVfQy4D9AEafLc1oEewUHfbLQEqpt/0qJRkw Z490y0u2zPootgbCrYOrvn1XTbUcspzA7A8AhAuDs6K9NjEAS3DCgs0OlPef65tRWlCy8S b7llLilmzVRLMR12rqhbQWRG+O22C34= X-MC-Unique: mfgaHG-pN3uVmRoftWLDuQ-1 X-Mimecast-MFC-AGG-ID: mfgaHG-pN3uVmRoftWLDuQ_1764251472 To: devel@lists.libvirt.org Subject: [PATCH 5/8] iptablesPrivateChainCreate: Rename @tmp variable Date: Thu, 27 Nov 2025 14:51:00 +0100 Message-ID: <61744133c2be469180dd34f19191f2a5aae704e3.1764251323.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: VZR2RkqNvhSYc9Tu5UtDhi2-uTnI4dK8pxQUCojX2Ts_1764251472 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: IDMEFWOX7ODKNIE7FS4APDWLAV4322XU X-Message-ID-Hash: IDMEFWOX7ODKNIE7FS4APDWLAV4322XU X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1764251925634019200 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik The iptablesPrivateChainCreate() function gets a NULL terminated array of strings (@lines argument), each item representing one line of iptables output. Currently, the variable used to iterate over the array is named 'tmp' which is not very descriptive. Rename it to 'line'. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko Tested-by: Jaroslav Suchanek --- src/network/network_iptables.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/network/network_iptables.c b/src/network/network_iptables.c index e8da15426e..be91b273ed 100644 --- a/src/network/network_iptables.c +++ b/src/network/network_iptables.c @@ -85,26 +85,27 @@ iptablesPrivateChainCreate(virFirewall *fw, iptablesGlobalChainData *data =3D opaque; g_autoptr(GHashTable) chains =3D virHashNew(NULL); g_autoptr(GHashTable) links =3D virHashNew(NULL); - const char *const *tmp; + const char *const *line; size_t i; =20 - tmp =3D lines; - while (tmp && *tmp) { - if (STRPREFIX(*tmp, "-N ")) { /* eg "-N LIBVIRT_INP" */ - if (virHashUpdateEntry(chains, *tmp + 3, (void *)0x1) < 0) + line =3D lines; + while (line && *line) { + if (STRPREFIX(*line, "-N ")) { /* eg "-N LIBVIRT_INP" */ + if (virHashUpdateEntry(chains, *line + 3, (void *)0x1) < 0) return -1; - } else if (STRPREFIX(*tmp, "-A ")) { /* eg "-A INPUT -j LIBVIRT_IN= P" */ - char *sep =3D strchr(*tmp + 3, ' '); + } else if (STRPREFIX(*line, "-A ")) { /* eg "-A INPUT -j LIBVIRT_I= NP" */ + char *sep =3D strchr(*line + 3, ' '); + if (sep) { *sep =3D '\0'; if (STRPREFIX(sep + 1, "-j ")) { if (virHashUpdateEntry(links, sep + 4, - (char *)*tmp + 3) < 0) + (char *)*line + 3) < 0) return -1; } } } - tmp++; + line++; } =20 for (i =3D 0; i < data->nchains; i++) { --=20 2.51.2 From nobody Fri Dec 12 12:53:26 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1764252101; cv=none; d=zohomail.com; s=zohoarc; b=gL9E8UdMTkAhE4gICYgvlo5TbaobagDvpKgPNhIrAPzYFVXKRAZoIYQzYkMysggqoFv1EGbEJpziLFrky6suydSyPkam/Shok70CtAwtIXlmoYC7kzUEZmzUrrus2Gbr8I5PptA9yIQpcISs183CwS6tovLFjpULIeBqAteZDX0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1764252101; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=9Q1unLuMyUl1Mf6OqSa6ka9PXwoyEJZEbseSlndALTc=; b=ZBqp0xfMUibWIEwTQNH5mAzUfjgQfaH7cWjPb0sB1GE1OoTyK5ybqD8Phl46cqFI0QVDH7Q5jQFreJvj3+XtBc53q0lwtUeDbdiw0fk4/IiV8vhewUJsFjVteved5ES2txcjCDCkn5Ph1AVhqpMsWjr6Kwdb3yIvkz3072DJsfo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1764252101775413.0751504658749; Thu, 27 Nov 2025 06:01:41 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id E3ECD44B38; Thu, 27 Nov 2025 09:01:40 -0500 (EST) Received: from [172.19.199.74] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id BD8E244D52; Thu, 27 Nov 2025 08:54:49 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id 468C543DBE; Thu, 27 Nov 2025 08:52:39 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 21714446B8 for ; Thu, 27 Nov 2025 08:51:16 -0500 (EST) Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-444-gfwN6o0oNKmjKraDyz3rew-1; Thu, 27 Nov 2025 08:51:14 -0500 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 96832195605A for ; Thu, 27 Nov 2025 13:51:13 +0000 (UTC) Received: from moe (unknown [10.43.3.236]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E09C01800451 for ; Thu, 27 Nov 2025 13:51:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1764251475; h=from:from: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; bh=9Q1unLuMyUl1Mf6OqSa6ka9PXwoyEJZEbseSlndALTc=; b=G5aefEWqP7JTSzzrrRKDevnPOT8ask1PAscG9dDuadh4gLzOxb6xlZJ1uvOOOjCUzrXu2L isJ6ppT7cMP1TRisrk8v7QwH8HKGmDLazNmGhRKNsXb0cEyqs5cJqTZF5XnQxuvXIpD0cj lOue224iIVJZZ/Brbqx8NGTwoPAQk04= X-MC-Unique: gfwN6o0oNKmjKraDyz3rew-1 X-Mimecast-MFC-AGG-ID: gfwN6o0oNKmjKraDyz3rew_1764251473 To: devel@lists.libvirt.org Subject: [PATCH 6/8] iptablesPrivateChainCreate: Switch to STRSKIP() Date: Thu, 27 Nov 2025 14:51:01 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: LtHI3QBFLelrIaWMBprzGP4_ev2Omp5BJj4rSYz2LiI_1764251473 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: M5QVMKR62TY4F3YVL3FAWDEB3F57HMGK X-Message-ID-Hash: M5QVMKR62TY4F3YVL3FAWDEB3F57HMGK X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1764252103117019200 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik The body of iptablesPrivateChainCreate() uses STRPREFIX() to match strings starting with certain prefix. Then it uses pointer arithmetic to skip the prefix. Well, that's exactly what STRSKIP() is meant to do. Switch the body to use the latter. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko Tested-by: Jaroslav Suchanek --- src/network/network_iptables.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/network/network_iptables.c b/src/network/network_iptables.c index be91b273ed..19dcfc7c8b 100644 --- a/src/network/network_iptables.c +++ b/src/network/network_iptables.c @@ -90,17 +90,21 @@ iptablesPrivateChainCreate(virFirewall *fw, =20 line =3D lines; while (line && *line) { - if (STRPREFIX(*line, "-N ")) { /* eg "-N LIBVIRT_INP" */ - if (virHashUpdateEntry(chains, *line + 3, (void *)0x1) < 0) + const char *tmp; + + if ((tmp =3D STRSKIP(*line, "-N "))) { /* eg "-N LIBVIRT_INP" */ + if (virHashUpdateEntry(chains, tmp, (void *)0x1) < 0) return -1; - } else if (STRPREFIX(*line, "-A ")) { /* eg "-A INPUT -j LIBVIRT_I= NP" */ - char *sep =3D strchr(*line + 3, ' '); + } else if ((tmp =3D STRSKIP(*line, "-A "))) { /* eg "-A INPUT -j L= IBVIRT_INP" */ + char *sep =3D strchr(tmp, ' '); =20 if (sep) { + char *target; + *sep =3D '\0'; - if (STRPREFIX(sep + 1, "-j ")) { - if (virHashUpdateEntry(links, sep + 4, - (char *)*line + 3) < 0) + if ((target =3D STRSKIP(sep + 1, "-j "))) { + if (virHashUpdateEntry(links, target, + (char *)tmp) < 0) return -1; } } --=20 2.51.2 From nobody Fri Dec 12 12:53:26 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1764252684; cv=none; d=zohomail.com; s=zohoarc; b=VK61ImY6GDpQG4rBfjWNQ2zJ3gNippXg3EMeygFOTnFH3c7QFwORVRf4K9xGmD7TXY4Fjxf3ZVo/PR0ltttkmDJCbU6cvQE2APhYN1Sa6FG8f36VsTs2xdErzvWhpfKJFp6K5uUxbeCK6gx5vaDUvJt7nWrHRluxLutC4SueW7U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1764252684; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=Hoiv3TRkLY50Ii3HyJOJ/nnOEHGLSh1IN1gM4cFbkXM=; b=kLxmf9RAvPmvh/DXWHKthQCrRKhB2tHOkzdl7nvgUg3R1XhvgN8lrL+hib3S5yIBkQ/AirUcpbZGnhLYsE0Mv3azh/Aly/Wi9RUvDGAwirPfPQbfNy5+xPnpngWWHFUFRvKqKNcQNlTa5J4OsiSaoDaYsW3WLS+mQSNqkZX38Hk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1764252684422165.89008177522453; Thu, 27 Nov 2025 06:11:24 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id 3F85744B79; Thu, 27 Nov 2025 09:00:40 -0500 (EST) Received: from [172.19.199.74] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 3AED644C56; Thu, 27 Nov 2025 08:54:34 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id 8DFC0418CA; Thu, 27 Nov 2025 08:52:38 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 0297044BCE for ; Thu, 27 Nov 2025 08:51:17 -0500 (EST) Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-446-vMaym0vdNqWbZgrHOXhogA-1; Thu, 27 Nov 2025 08:51:15 -0500 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B6F5A195608A for ; Thu, 27 Nov 2025 13:51:14 +0000 (UTC) Received: from moe (unknown [10.43.3.236]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0C58B1800346 for ; Thu, 27 Nov 2025 13:51:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1764251477; h=from:from: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; bh=Hoiv3TRkLY50Ii3HyJOJ/nnOEHGLSh1IN1gM4cFbkXM=; b=OQSGtBmVdRoqbr3r6cLTrYwWNl3GX/Uk3/RAzcGFHzGXAiiKjj+S1YDFWB0QNYLU1e5Hlv n3vnPhjAgMTkWMiIV94OZBcpVcup5H6ol89X3uKbCHQIkWCkx3fYLA3pNPBmb8lpmR4VMf FzqcDpsbM1ekbtwsLzOlV6dNYHOZsV0= X-MC-Unique: vMaym0vdNqWbZgrHOXhogA-1 X-Mimecast-MFC-AGG-ID: vMaym0vdNqWbZgrHOXhogA_1764251474 To: devel@lists.libvirt.org Subject: [PATCH 7/8] iptablesPrivateChainCreate: Avoid modifying const string Date: Thu, 27 Nov 2025 14:51:02 +0100 Message-ID: <2ec89ac0de961234e0a7f5d56cc4fc6f97c69ef9.1764251323.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: r5dXKfdynhLwRTZ3b0KTXqdoerjPobrtDNtjqyOM1xc_1764251474 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: B4GS44E7RCNP2T372PTPYGO5LFK5LSTB X-Message-ID-Hash: B4GS44E7RCNP2T372PTPYGO5LFK5LSTB X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1764252685709019200 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik The iptablesPrivateChainCreate() function is given an array of const strings. This constitutes a promise to the caller that the data is not modified. But inside the data is modified anyway (to cut out some parts of the data). Well, with a help from g_strdup() the promise can be kept. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko Tested-by: Jaroslav Suchanek --- src/network/network_iptables.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/network/network_iptables.c b/src/network/network_iptables.c index 19dcfc7c8b..d21ce59b70 100644 --- a/src/network/network_iptables.c +++ b/src/network/network_iptables.c @@ -84,7 +84,7 @@ iptablesPrivateChainCreate(virFirewall *fw, { iptablesGlobalChainData *data =3D opaque; g_autoptr(GHashTable) chains =3D virHashNew(NULL); - g_autoptr(GHashTable) links =3D virHashNew(NULL); + g_autoptr(GHashTable) links =3D virHashNew(g_free); const char *const *line; size_t i; =20 @@ -96,16 +96,18 @@ iptablesPrivateChainCreate(virFirewall *fw, if (virHashUpdateEntry(chains, tmp, (void *)0x1) < 0) return -1; } else if ((tmp =3D STRSKIP(*line, "-A "))) { /* eg "-A INPUT -j L= IBVIRT_INP" */ - char *sep =3D strchr(tmp, ' '); + const char *sep =3D strchr(tmp, ' '); =20 if (sep) { - char *target; + const char *target; =20 - *sep =3D '\0'; if ((target =3D STRSKIP(sep + 1, "-j "))) { - if (virHashUpdateEntry(links, target, - (char *)tmp) < 0) + char *chain =3D g_strndup(tmp, sep - tmp); + + if (virHashUpdateEntry(links, target, chain) < 0) { + g_free(chain); return -1; + } } } } --=20 2.51.2 From nobody Fri Dec 12 12:53:26 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1764252251; cv=none; d=zohomail.com; s=zohoarc; b=NpXmbyZiElDSuj/HoFM1AQgmQWm8rdcFxAoSwgLC8G4mRN2hCQAr5ugmHDZemcRgQ6NDG/lpHRvrJ8KuP29Nlsn8Kpttx3YF/LoH0w1GZbaG08cJpn6Hn4DRUmXARXERx9R4mFB5sLCsrv+yaPITOAIjMjWZRcZT+TKjVGqONF8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1764252251; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=KXtHhTdBTStlWs88xnerqcG2Y/3aET6czTjiRyPX0hE=; b=H2bOD6m3RPEOHhU7YKP6/TxsL4aZzCMHlabiMjCCHAABcWGVKymYMAtmGikRwRdNnN9IKUft601WdQK58rVMvcpSOGnTXpleFWzCnWDB7YzTbG1nebj5cpBvk7vj/ZNwO1yxz+cICBCgu2Z8h4qCBauDaDvCYjEr/kxLE//KCb0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1764252244791876.7202026607151; Thu, 27 Nov 2025 06:04:04 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id CCA6C44B60; Thu, 27 Nov 2025 09:03:59 -0500 (EST) Received: from [172.19.199.74] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 2ACF444D90; Thu, 27 Nov 2025 08:55:49 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id C908041996; Thu, 27 Nov 2025 08:52:39 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 6428F44BE0 for ; Thu, 27 Nov 2025 08:51:18 -0500 (EST) Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-47-RxtVnZYdPHmrbL52uT6pSQ-1; Thu, 27 Nov 2025 08:51:16 -0500 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0038C180049F for ; Thu, 27 Nov 2025 13:51:16 +0000 (UTC) Received: from moe (unknown [10.43.3.236]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2C64E1800451 for ; Thu, 27 Nov 2025 13:51:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1764251478; h=from:from: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; bh=KXtHhTdBTStlWs88xnerqcG2Y/3aET6czTjiRyPX0hE=; b=Rc1w7szOpVqASWan0lXk4v78p8Apf1rwn79gdkFbKb+Nh7kY/pRgzfZFPfOANv/1So0pIY djWQnwCmuJSGsQtqUMRF2Ce2JFE72h6xXJpuvsRoblLPjx7iRobJRWPl75qPSndAhLI503 FX179cJP/qq6X/NcwwfLeWaXjPTpQww= X-MC-Unique: RxtVnZYdPHmrbL52uT6pSQ-1 X-Mimecast-MFC-AGG-ID: RxtVnZYdPHmrbL52uT6pSQ_1764251476 To: devel@lists.libvirt.org Subject: [PATCH 8/8] lib: Avoid changing const strings via strchr() and friends Date: Thu, 27 Nov 2025 14:51:03 +0100 Message-ID: <8efac77783661f47efba79021eb2e9801c3194ce.1764251323.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 83neDsU8FLU6PdIzrRHg_SAWICrtTh6FjSPODZEiMTw_1764251476 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 6FRIEFQBQKFQB3W5F5ETU6CN4UBY5Q4Q X-Message-ID-Hash: 6FRIEFQBQKFQB3W5F5ETU6CN4UBY5Q4Q X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1764252256016019200 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik There's new commit in glibc [1] which makes memchr(), strchr(), strrchr(), strpbrk() and strstr() reflect type of the input string. If it's a constant string, then the return type of these functions is also 'const char *'. But this change tickles -Wincompatible-pointer-types-discards-qualifiers warning. And indeed, there are some places where we use a 'char *' typed variable to store the retval, or even misuse the fact 'char *' is returned and modify const string. To fix this, a couple of different approaches is used: a) switch variable type to 'const char *', b) switch argument to 'char *' (in a few places we have strdup()-ed) the const string already, c) strdup() the string and use b). 1: https://sourceware.org/git/?p=3Dglibc.git;a=3Dcommit;h=3Dcd748a63ab1a7ae= 846175c532a3daab341c62690 Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko Tested-by: Jaroslav Suchanek --- src/interface/interface_backend_udev.c | 2 +- src/libxl/xen_common.c | 10 +++++----- src/libxl/xen_xm.c | 10 ++++++---- src/node_device/node_device_udev.c | 2 +- src/nwfilter/nwfilter_ebiptables_driver.c | 4 ++-- src/qemu/qemu_monitor_json.c | 2 +- src/qemu/qemu_nbdkit.c | 2 +- src/rpc/virnetsshsession.c | 5 +++-- src/storage/storage_util.c | 2 +- src/storage_file/storage_source.c | 4 ++-- src/util/vircgroup.c | 2 +- src/util/virfile.c | 2 +- src/util/virstoragefile.c | 4 ++-- src/util/virsysinfo.c | 8 ++++---- src/util/virxml.c | 3 ++- src/vmware/vmware_conf.c | 2 +- tools/vsh.c | 6 +++--- 17 files changed, 37 insertions(+), 33 deletions(-) diff --git a/src/interface/interface_backend_udev.c b/src/interface/interfa= ce_backend_udev.c index 48eacdcdc2..c6d14aa803 100644 --- a/src/interface/interface_backend_udev.c +++ b/src/interface/interface_backend_udev.c @@ -927,7 +927,7 @@ udevGetIfaceDef(struct udev *udev, const char *name) g_autoptr(virInterfaceDef) ifacedef =3D NULL; unsigned int mtu; const char *mtu_str; - char *vlan_parent_dev =3D NULL; + const char *vlan_parent_dev =3D NULL; const char *devtype; =20 /* Allocate our interface definition structure */ diff --git a/src/libxl/xen_common.c b/src/libxl/xen_common.c index 666c6cae20..890ef11723 100644 --- a/src/libxl/xen_common.c +++ b/src/libxl/xen_common.c @@ -802,20 +802,20 @@ static virDomainChrDef * xenParseSxprChar(const char *value, const char *tty) { - const char *prefix; + g_autofree char *prefix =3D NULL; char *tmp; virDomainChrDef *def; =20 if (!(def =3D virDomainChrDefNew(NULL))) return NULL; =20 - prefix =3D value; + prefix =3D g_strdup(value); =20 if (g_path_is_absolute(value)) { def->source->type =3D VIR_DOMAIN_CHR_TYPE_DEV; def->source->data.file.path =3D g_strdup(value); } else { - if ((tmp =3D strchr(value, ':')) !=3D NULL) { + if ((tmp =3D strchr(prefix, ':')) !=3D NULL) { *tmp =3D '\0'; value =3D tmp + 1; } @@ -1019,7 +1019,7 @@ xenParseCharDev(virConf *conf, virDomainDef *def, con= st char *nativeFormat) static int xenParseVifBridge(virDomainNetDef *net, const char *bridge) { - char *vlanstr; + const char *vlanstr; unsigned int tag; =20 if ((vlanstr =3D strchr(bridge, '.'))) { @@ -1144,7 +1144,7 @@ xenParseVif(char *entry, const char *vif_typename) =20 for (keyval =3D keyvals; keyval && *keyval; keyval++) { const char *key =3D *keyval; - char *val =3D strchr(key, '=3D'); + const char *val =3D strchr(key, '=3D'); =20 virSkipSpaces(&key); =20 diff --git a/src/libxl/xen_xm.c b/src/libxl/xen_xm.c index 274b35153b..4327a9391d 100644 --- a/src/libxl/xen_xm.c +++ b/src/libxl/xen_xm.c @@ -154,9 +154,11 @@ xenParseXMDisk(char *entry, int hvm) src =3D virDomainDiskGetSource(disk); if (src) { size_t len; + const char *sep; + /* The main type phy:, file:, tap: ... */ - if ((tmp =3D strchr(src, ':')) !=3D NULL) { - len =3D tmp - src; + if ((sep =3D strchr(src, ':')) !=3D NULL) { + len =3D sep - src; tmp =3D g_strndup(src, len); =20 virDomainDiskSetDriver(disk, tmp); @@ -173,9 +175,9 @@ xenParseXMDisk(char *entry, int hvm) STREQ_NULLABLE(virDomainDiskGetDriver(disk), "tap2")) { char *driverType; =20 - if (!(tmp =3D strchr(src, ':'))) + if (!(sep =3D strchr(src, ':'))) goto error; - len =3D tmp - src; + len =3D sep - src; =20 driverType =3D g_strndup(src, len); =20 diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 27e62febe8..20a525bcec 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1187,7 +1187,7 @@ static int udevGetCCWAddress(const char *sysfs_path, virNodeDevCapData *data) { - char *p; + const char *p; g_autofree virCCWDeviceAddress *ccw_addr =3D g_new0(virCCWDeviceAddres= s, 1); =20 if ((p =3D strrchr(sysfs_path, '/')) =3D=3D NULL || diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c b/src/nwfilter/nwfil= ter_ebiptables_driver.c index 4578152670..859347409c 100644 --- a/src/nwfilter/nwfilter_ebiptables_driver.c +++ b/src/nwfilter/nwfilter_ebiptables_driver.c @@ -2604,7 +2604,7 @@ ebtablesRemoveSubChainsQuery(virFirewall *fw, const char *chainprefixes =3D opaque; =20 for (i =3D 0; lines[i] !=3D NULL; i++) { - char *tmp =3D strstr(lines[i], "-j "); + const char *tmp =3D strstr(lines[i], "-j "); =20 VIR_DEBUG("Considering '%s'", lines[i]); =20 @@ -2708,7 +2708,7 @@ ebtablesRenameTmpSubAndRootChainsQuery(virFirewall *f= w, char newchain[MAX_CHAINNAME_LENGTH]; =20 for (i =3D 0; lines[i] !=3D NULL; i++) { - char *tmp =3D strstr(lines[i], "-j "); + const char *tmp =3D strstr(lines[i], "-j "); =20 VIR_DEBUG("Considering '%s'", lines[i]); =20 diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 494d7ef515..a602b1e65b 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -241,7 +241,7 @@ qemuMonitorJSONIOProcess(qemuMonitor *mon, /*VIR_DEBUG("Data %d bytes [%s]", len, data);*/ =20 while (used < len) { - char *nl =3D strstr(data + used, LINE_ENDING); + const char *nl =3D strstr(data + used, LINE_ENDING); =20 if (nl) { int got =3D nl - (data + used); diff --git a/src/qemu/qemu_nbdkit.c b/src/qemu/qemu_nbdkit.c index c1bc6bc363..542a6b1f44 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -146,7 +146,7 @@ qemuNbdkitCapsQueryBuildConfig(qemuNbdkitCaps *nbdkit) size_t i; g_autofree char *output =3D NULL; g_auto(GStrv) lines =3D NULL; - const char *line; + char *line; g_autoptr(virCommand) cmd =3D virCommandNewArgList(nbdkit->path, "--dump-config", NULL); diff --git a/src/rpc/virnetsshsession.c b/src/rpc/virnetsshsession.c index 316521d4cf..83c8630480 100644 --- a/src/rpc/virnetsshsession.c +++ b/src/rpc/virnetsshsession.c @@ -216,13 +216,14 @@ virNetSSHKbIntCb(const char *name G_GNUC_UNUSED, =20 /* fill data structures for auth callback */ for (i =3D 0; i < num_prompts; i++) { - askcred[i].prompt =3D g_strdup((char*)prompts[i].text); + char *prompt =3D g_strdup((char*)prompts[i].text); =20 /* remove colon and trailing spaces from prompts, as default behav= ior * of libvirt's auth callback is to add them */ - if ((tmp =3D strrchr(askcred[i].prompt, ':'))) + if ((tmp =3D strrchr(prompt, ':'))) *tmp =3D '\0'; =20 + askcred[i].prompt =3D prompt; askcred[i].type =3D prompts[i].echo ? credtype_echo : credtype_noe= cho; } =20 diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 8f7fc6cc01..e2b41de1f2 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -3773,7 +3773,7 @@ getOldStyleBlockDevice(const char *lun_path G_GNUC_UN= USED, const char *block_name, char **block_device) { - char *blockp =3D NULL; + const char *blockp =3D NULL; =20 /* old-style; just parse out the sd */ if (!(blockp =3D strrchr(block_name, ':'))) { diff --git a/src/storage_file/storage_source.c b/src/storage_file/storage_s= ource.c index 843910a0d8..1883225a8b 100644 --- a/src/storage_file/storage_source.c +++ b/src/storage_file/storage_source.c @@ -45,8 +45,8 @@ VIR_LOG_INIT("storage_source"); static bool virStorageSourceBackinStoreStringIsFile(const char *backing) { - char *colon; - char *slash; + const char *colon; + const char *slash; =20 if (!backing) return false; diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 532a7e5690..3d66d3acb2 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -517,7 +517,7 @@ int virCgroupSetValueRaw(const char *path, const char *value) { - char *tmp; + const char *tmp; =20 VIR_DEBUG("Set path '%s' to value '%s'", path, value); if (virFileWriteStr(path, value, 0) < 0) { diff --git a/src/util/virfile.c b/src/util/virfile.c index a5c9fbe0d9..f195d02e29 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -3359,7 +3359,7 @@ char * virFileSanitizePath(const char *path) { const char *cur =3D path; - char *uri; + const char *uri; char *cleanpath; int idx =3D 0; =20 diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 031baa1407..22bda87643 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -119,8 +119,8 @@ virStorageFileGetNPIVKey(const char *path, char **key) { int status; - const char *serial; - const char *port; + char *serial; + char *port; g_autofree char *outbuf =3D NULL; g_autoptr(virCommand) cmd =3D NULL; =20 diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c index c017ad34b7..b638fbd16c 100644 --- a/src/util/virsysinfo.c +++ b/src/util/virsysinfo.c @@ -219,7 +219,7 @@ static int virSysinfoParsePPCSystem(const char *base, virSysinfoSystemDef **sysdef) { int ret =3D -1; - char *eol =3D NULL; + const char *eol =3D NULL; const char *cur; virSysinfoSystemDef *def; =20 @@ -267,7 +267,7 @@ static void virSysinfoParsePPCProcessor(const char *base, virSysinfoDef *ret) { const char *cur; - char *eol, *tmp_base; + const char *eol, *tmp_base; virSysinfoProcessorDef *processor; =20 while ((tmp_base =3D strstr(base, "processor")) !=3D NULL) { @@ -336,7 +336,7 @@ static int virSysinfoParseARMSystem(const char *base, virSysinfoSystemDef **sysdef) { int ret =3D -1; - char *eol =3D NULL; + const char *eol =3D NULL; const char *cur; virSysinfoSystemDef *def; =20 @@ -384,7 +384,7 @@ static void virSysinfoParseARMProcessor(const char *base, virSysinfoDef *ret) { const char *cur; - char *eol, *tmp_base; + const char *eol, *tmp_base; virSysinfoProcessorDef *processor; char *processor_type =3D NULL; =20 diff --git a/src/util/virxml.c b/src/util/virxml.c index 77c7b5a8f4..274f072598 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -368,7 +368,8 @@ virXMLCheckIllegalChars(const char *nodeName, const char *str, const char *illegal) { - char *c; + const char *c; + if ((c =3D strpbrk(str, illegal))) { virReportError(VIR_ERR_XML_DETAIL, _("invalid char in %1$s: %2$c"), nodeName, *c); diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c index a598b512dc..11db044b52 100644 --- a/src/vmware/vmware_conf.c +++ b/src/vmware/vmware_conf.c @@ -305,7 +305,7 @@ vmwareDomainConfigDisplay(vmwareDomainPtr pDomain, virD= omainDef *def) static int vmwareParsePath(const char *path, char **directory, char **filename) { - char *separator; + const char *separator; =20 separator =3D strrchr(path, '/'); =20 diff --git a/tools/vsh.c b/tools/vsh.c index 4aacc5feac..69d3930e43 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -413,7 +413,7 @@ vshCmddefCheckInternals(vshControl *ctl, case VSH_OT_ALIAS: { size_t j; g_autofree char *name =3D NULL; - char *p; + const char *p; =20 if (opt->required || opt->positional || @@ -502,7 +502,7 @@ vshCmdGetOption(vshControl *ctl, alias of option and its default value */ alias =3D g_strdup(n->def->help); name =3D alias; - if ((value =3D strchr(name, '=3D'))) { + if ((value =3D strchr(alias, '=3D'))) { *value =3D '\0'; if (*optstr) { if (report) @@ -1660,7 +1660,7 @@ vshCommandParse(vshControl *ctl, * value * -- (terminate accepting '--option', fill only positional = args) */ - const char *optionname =3D tkdata + 2; + char *optionname =3D tkdata + 2; char *sep; =20 if (!STRPREFIX(tkdata, "--")) { --=20 2.51.2