From nobody Mon Sep 16 19:20:13 2024 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1716969141366158.96301029476535; Wed, 29 May 2024 00:52:21 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 486E01A9E; Wed, 29 May 2024 03:52:20 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id CD5FE1A51; Wed, 29 May 2024 03:51:42 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 90B691A6E; Wed, 29 May 2024 03:51:40 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 1E4631A51 for ; Wed, 29 May 2024 03:51:40 -0400 (EDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-493-yF7Y5WIAP_mhP3nFndVjpg-1; Wed, 29 May 2024 03:51:38 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id C11AC800281 for ; Wed, 29 May 2024 07:51:37 +0000 (UTC) Received: from maggie.brq.redhat.com (unknown [10.43.3.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6BEAD40C6EB7 for ; Wed, 29 May 2024 07:51:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716969099; 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; bh=lcnJ2HV/MKn9wFp41v32qfw6F6PsK97G/+xNj3vU7RI=; b=E356jK/zWxuTLnYDmDQfDuJhC/rxKFvMD+7G3MB7Lbq3xbn0lWh5b0JzRcbQyDIUO8kk82 /CEcaYX2idQUZQluMLw3xzEhgoktGuCyBhjXLud6coa8vrnCnbgnk90hN3uTBzIeqc2NuL asxsUVfnTdFJznIv1xYhI/hjgBFYCBE= X-MC-Unique: yF7Y5WIAP_mhP3nFndVjpg-1 From: Michal Privoznik To: devel@lists.libvirt.org Subject: [PATCH] log_cleaner: Detect rotated filenames properly Date: Wed, 29 May 2024 09:51:36 +0200 Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: ZWZ7GFFLZTCMWDUUB3X4FFK4YT5LW4OA X-Message-ID-Hash: ZWZ7GFFLZTCMWDUUB3X4FFK4YT5LW4OA X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1716969143285100001 Content-Type: text/plain; charset="utf-8"; x-default="true" When removing rotated log files, their name is matched against a regex (@log_regex) and if they contain '.N' suffix the 'N' is then parsed into an integer. Well, due to a bug in virLogCleanerParseFilename() this is not how the code works. If the suffix isn't found then g_match_info_fetch() returns an empty string instead of NULL which then makes str2int parsing fail. Just check for this case before parsing the string. Based on the original patch sent by David. Reported-by: David Negreira Signed-off-by: Michal Privoznik Reviewed-by: Jiri Denemark --- The original patch was posted here: https://lists.libvirt.org/archives/list/devel@lists.libvirt.org/thread/ENXJ= ABODLWWXAR6RSKGMG6GAJKZMVKKM/ In the thread you can see me suggesting this alternative approach and David confirming it works. Therefore, I'd like to get this in before the release. src/logging/log_cleaner.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/logging/log_cleaner.c b/src/logging/log_cleaner.c index 4ee91843aa..4efcbc18e4 100644 --- a/src/logging/log_cleaner.c +++ b/src/logging/log_cleaner.c @@ -82,10 +82,8 @@ virLogCleanerParseFilename(const char *path, *rotated_index =3D 0; rotated_index_str =3D g_match_info_fetch(matchInfo, 3); =20 - if (!rotated_index_str) - return chain_prefix; - - if (virStrToLong_i(rotated_index_str, NULL, 10, rotated_index) < 0) { + if (rotated_index_str && STRNEQ(rotated_index_str, "") && + virStrToLong_i(rotated_index_str, NULL, 10, rotated_index) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to parse rotated index from '%1$s'"), rotated_index_str); --=20 2.44.1