From nobody Fri Mar 29 05:10:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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=1574948473; cv=none; d=zohomail.com; s=zohoarc; b=ceqzl3AFkEzea9PjtHd6qqg2lizUJZpjnKNNQigB6k85lwLYWctUMo69XCBo1veS4kcfmvA/3TywrEhKhssCB4iK3v2ogvHLVDFVP1x8uKK/FJmkQhn4C0hQRSZuy/i7nQSpx9oqXCdhLs660M362gd7Y7ikI0edx/BNOfzWF9k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1574948473; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=3zNRMRDkG3A0i/3tdb99tu3qW5KClxhGsO5rLKPAOTk=; b=jozYmpVJiIhatyR5pzfdYOFPsVaRbJvAq7H8n/MQWsp2oqtCIUF2ebQ+PVnKiMyLOKJh/rcecSpYO6g3IuzFkGmOJqxH9cUwOONd8HfVw9nHHanPA3Ppr4L5UOx4IRG/1AASr35+a9oRZ2iJMJMqhTQzPfh4gp7C3Ain0kIy50E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1574948473245451.5288696699894; Thu, 28 Nov 2019 05:41: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-299-8g3MhIraMMmJsNSIf4IW0w-1; Thu, 28 Nov 2019 08:41:10 -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 74782107ACC5; Thu, 28 Nov 2019 13:41:04 +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 E36265D9E1; Thu, 28 Nov 2019 13:41:03 +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 6F5C018095FF; Thu, 28 Nov 2019 13:41:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xASDf0Ua009787 for ; Thu, 28 Nov 2019 08:41:00 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2A39C5C21B; Thu, 28 Nov 2019 13:41:00 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 812CE5C1B0; Thu, 28 Nov 2019 13:40:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574948472; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=3zNRMRDkG3A0i/3tdb99tu3qW5KClxhGsO5rLKPAOTk=; b=c0VsaeIixBjhVjRF7/pqNUSFv+Aas6BT17rjc5/iIYPttlj6OjXqjqzQGIOPq3F+ky9wGU mpD/0hUTEgpqsgpLCXJaj8a7DYbf0R4kz6nynBRSWc8C0tZmo4/aEpzCY1d1tMZLl9GGSq 1So+oXN1NQ8JkVD/YAEL9PF1m1uHjcE= From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 28 Nov 2019 14:40:55 +0100 Message-Id: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: phrdina@redhat.com Subject: [libvirt] [PATCH for 5.10.0] nss: Don't fail on empty files 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 X-MC-Unique: 8g3MhIraMMmJsNSIf4IW0w-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Before we rewrote nss plugin so that it doesn't use libvirt's internal functions it used virLeaseReadCustomLeaseFile() to parse .status files. After the rewrite it's using read() + yajl_parse() + yajl_complete_parse(). There's one catch though, virLeaseReadCustomLeaseFile() skipped over empty files. An empty .status file is created when a network is started. This is because we configure dnsmasq to use our leasehelper. So the first thing it does it calls it as follows: DNSMASQ_INTERFACE=3Dvirbr0 /usr/libexec/libvirt_leaseshelper init which causes the leasehelper to create empty virbr0.status file. If there is only one libvirt network then that is no problem - there are no other .status files to parse anyway. But if there are two or more networks then the first empty .status file causes whole parsing process and subsequently the whole name lookup process to fail. Reported-by: Pavel Hrdina Signed-off-by: Michal Privoznik Reviewed-by: Daniel P. Berrang=C3=A9 --- tools/nss/libvirt_nss_leases.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/nss/libvirt_nss_leases.c b/tools/nss/libvirt_nss_leases.c index e96e260da8..7c431e4d53 100644 --- a/tools/nss/libvirt_nss_leases.c +++ b/tools/nss/libvirt_nss_leases.c @@ -379,6 +379,7 @@ findLeases(const char *file, }; yajl_handle parser =3D NULL; char line[1024]; + ssize_t nreadTotal =3D 0; int rv; =20 if ((fd =3D open(file, O_RDONLY)) < 0) { @@ -398,6 +399,7 @@ findLeases(const char *file, goto cleanup; if (rv =3D=3D 0) break; + nreadTotal +=3D rv; =20 if (yajl_parse(parser, (const unsigned char *)line, rv) !=3D yajl_status_ok) { @@ -409,7 +411,8 @@ findLeases(const char *file, } } =20 - if (yajl_complete_parse(parser) !=3D yajl_status_ok) { + if (nreadTotal > 0 && + yajl_complete_parse(parser) !=3D yajl_status_ok) { ERROR("Parse failed %s", yajl_get_error(parser, 1, NULL, 0)); goto cleanup; --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list