From nobody Tue Jan 21 03:59:06 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=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1737368561888438.13601766780096; Mon, 20 Jan 2025 02:22:41 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 3AD30191E; Mon, 20 Jan 2025 05:22:41 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 96BF918F5; Mon, 20 Jan 2025 05:22:26 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 4E5AB1A9D; Sat, 18 Jan 2025 03:33:33 -0500 (EST) Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (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 CD2F81A91 for ; Sat, 18 Jan 2025 03:33:28 -0500 (EST) Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-2167141dfa1so52346855ad.1 for ; Sat, 18 Jan 2025 00:33:28 -0800 (PST) Received: from desktop.lan ([112.32.32.142]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21c2d3e8081sm27506685ad.185.2025.01.18.00.33.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Jan 2025 00:33:27 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737189207; x=1737794007; darn=lists.libvirt.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=uR8qlxmQQoYY88B+ZYGmfgEAcwUotAdPDredwoNWiq0=; b=fWRQsAHY8EKaadjAfy/Ctr0ohygZF4reI82iiWyAa8B0gKag4OFgMQdz0la+ITMz+S x2PkSL4v4ErQfPleOqlPPNqeP2XuuPaSFKMCnUGhM1vcu41sHJIcJKvX6S1bPY0BH8dI JawdiQde8bvEFT/ug68/ST10ZagNuckv7kDif4QzD+9s/Nle/Gd4SZRVw+E7sZVK8DlU CIsWx2EqRkodvbxGDrbTyUgi5e0DcylLIoiN0YcCLQ/Sqe+uo+LsfRS2ConjzsPDPfJ2 JJWYaiLF3KjoKLrN6LKScLiE+R84a3uKNTeO6LH3wvAiTH78WtvyfBg03IBFTodeSo4R DwRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737189207; x=1737794007; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=uR8qlxmQQoYY88B+ZYGmfgEAcwUotAdPDredwoNWiq0=; b=bJfI9XvRsJ9x8eQS8oDU7fmnjTKBbavyALeFcAAfxC8aWvRjCk6fMnNmrtnmRNgiqM 53Mk6ye/LsRSRKBJvaE9cyWb+6pihBJ3TQlEa1dmbAnxRKsEbk5eO1/b/zLVf/TOAtSQ bA0xszEgUtvXjovQnrHne+ioQQGhLAvTXgMxHkW9PPtlVB54VcbDPyY4qwCmug7FBEJA r6tNYdB7hFMqg0AWggImq+axW/UISADa/6YcCdGJBLpxRyt3pxE6POZpvo0JNL2nxZOY Qqk6QwfNJAhDTRqtcLdafBH8e8c/wWwupl3aq5CjembcvExc1jsx8z0uFTJkWq/RU0pr S3YA== X-Gm-Message-State: AOJu0YwAY1sqhU7/ZnQfH0Fb1PqEnIPXJtD+stbhMdncCD1qNWvW/53o HUzEOGS9Q+km/HTCC7xh9C2FgY2WUxcoi/sJOhaE89OCIoMri0WYBsFf38n61YY= X-Gm-Gg: ASbGncuuGQg5uZsp+1XaIcNkaugVUNSRmihXITAhgHsQi7vR8UFmsjuMEOKeaA4HhXu QdX3BJHYgP/e6Adtv18PYwAGFEox9H24ZH2yja3fYuDpJ3+6N84ciJh28GLebcvrExyKQTc2jGn WKSsl2XYNFlTvFZqeNBQqZsx5GmxBCsu3/s7AusRWdMamiHR0QaPraN3kVPxV4myd8K2O3lOxm3 /1ndprz1fyrNtJyWGiBdGFYgqHsA2OS50tb0g99kCs/PUK4mkXuXOi77gQpmXqjaDXHSGaQ X-Google-Smtp-Source: AGHT+IE98ovZn978K28gLknCT076a/FfCL/UW1n9MBd8Q40T1OO0tjMzbKCP7ZRLqq/prcZ3QeT+vA== X-Received: by 2002:a17:903:2452:b0:216:59f1:c7d9 with SMTP id d9443c01a7336-21c36e5f763mr84451025ad.19.1737189207407; Sat, 18 Jan 2025 00:33:27 -0800 (PST) From: Jiang XueQian To: devel@lists.libvirt.org Subject: [PATCH] nss: Skip empty files and avoid use of uninitialized value Date: Sat, 18 Jan 2025 16:32:10 +0800 Message-ID: <20250118083305.444320-1-jiangxueqian@gmail.com> X-Mailer: git-send-email 2.48.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MailFrom: jiangxueqian@gmail.com X-Mailman-Rule-Hits: nonmember-moderation 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 Message-ID-Hash: E7RBL26OR7RNNBRAJJOFDVQ5VBZ7I3S7 X-Message-ID-Hash: E7RBL26OR7RNNBRAJJOFDVQ5VBZ7I3S7 X-Mailman-Approved-At: Mon, 20 Jan 2025 10:22:24 -0500 CC: Jiang XueQian 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: 1737368563183019000 Content-Type: text/plain; charset="utf-8" JSON parser isn't called when reading empty files so `jerr` will be used uninitialized in the original code. Empty files appear when a network has no dhcp clients. This patch checks for such files and skip them. Signed-off-by: Jiang XueQian --- tools/nss/libvirt_nss_leases.c | 5 +++++ tools/nss/libvirt_nss_macs.c | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/tools/nss/libvirt_nss_leases.c b/tools/nss/libvirt_nss_leases.c index aea81bb56e..7ffe4a8761 100644 --- a/tools/nss/libvirt_nss_leases.c +++ b/tools/nss/libvirt_nss_leases.c @@ -290,6 +290,11 @@ findLeases(const char *file, jerr =3D json_tokener_get_error(tok); } while (jerr =3D=3D json_tokener_continue); =20 + if (nreadTotal =3D=3D 0) { + ret =3D 0; + goto cleanup; + } + if (jerr =3D=3D json_tokener_continue) { ERROR("Cannot parse %s: incomplete json found", file); goto cleanup; diff --git a/tools/nss/libvirt_nss_macs.c b/tools/nss/libvirt_nss_macs.c index 23229a18f3..57c0f79fbb 100644 --- a/tools/nss/libvirt_nss_macs.c +++ b/tools/nss/libvirt_nss_macs.c @@ -152,6 +152,11 @@ findMACs(const char *file, jerr =3D json_tokener_get_error(tok); } while (jerr =3D=3D json_tokener_continue); =20 + if (nreadTotal =3D=3D 0) { + ret =3D 0; + goto cleanup; + } + if (jerr =3D=3D json_tokener_continue) { ERROR("Cannot parse %s: incomplete json found", file); goto cleanup; --=20 2.48.1