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 <jiangxueqian@gmail.com>
---
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 = json_tokener_get_error(tok);
} while (jerr == json_tokener_continue);
+ if (nreadTotal == 0) {
+ ret = 0;
+ goto cleanup;
+ }
+
if (jerr == 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 = json_tokener_get_error(tok);
} while (jerr == json_tokener_continue);
+ if (nreadTotal == 0) {
+ ret = 0;
+ goto cleanup;
+ }
+
if (jerr == json_tokener_continue) {
ERROR("Cannot parse %s: incomplete json found", file);
goto cleanup;
--
2.48.1