[libvirt PATCH] json: do not call json_tokener_free with NULL
by Ján Tomko
Add an error message for the rare case if json_tokener_new
fails (allocation failure) and guard any use of json_tokener_free
where tok might be NULL (this was possible in libvirt-nss
when the json file could not be opened).
https://gitlab.com/libvirt/libvirt/-/issues/581
Signed-off-by: Ján Tomko <jtomko(a)redhat.com>
Reported-by: Simon Pilkington
---
src/util/virjson.c | 8 +++++++-
tools/nss/libvirt_nss_leases.c | 7 ++++++-
tools/nss/libvirt_nss_macs.c | 7 ++++++-
3 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/src/util/virjson.c b/src/util/virjson.c
index 4a95e84f5b..18a4585e7b 100644
--- a/src/util/virjson.c
+++ b/src/util/virjson.c
@@ -1462,6 +1462,11 @@ virJSONValueFromString(const char *jsonstring)
VIR_DEBUG("string=%s", jsonstring);
tok = json_tokener_new();
+ if (!tok) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("failed to create JSON tokener"));
+ return NULL;
+ }
json_tokener_set_flags(tok, jsonflags);
jobj = json_tokener_parse_ex(tok, jsonstring, strlen(jsonstring));
jerr = json_tokener_get_error(tok);
@@ -1475,7 +1480,8 @@ virJSONValueFromString(const char *jsonstring)
cleanup:
json_object_put(jobj);
- json_tokener_free(tok);
+ if (tok)
+ json_tokener_free(tok);
return ret;
}
diff --git a/tools/nss/libvirt_nss_leases.c b/tools/nss/libvirt_nss_leases.c
index 01e965c4a1..aea81bb56e 100644
--- a/tools/nss/libvirt_nss_leases.c
+++ b/tools/nss/libvirt_nss_leases.c
@@ -272,6 +272,10 @@ findLeases(const char *file,
}
tok = json_tokener_new();
+ if (!tok) {
+ ERROR("failed to create JSON tokener");
+ goto cleanup;
+ }
json_tokener_set_flags(tok, jsonflags);
do {
@@ -301,7 +305,8 @@ findLeases(const char *file,
cleanup:
json_object_put(jobj);
- json_tokener_free(tok);
+ if (tok)
+ json_tokener_free(tok);
if (ret != 0) {
free(*addrs);
*addrs = NULL;
diff --git a/tools/nss/libvirt_nss_macs.c b/tools/nss/libvirt_nss_macs.c
index 430023abec..23229a18f3 100644
--- a/tools/nss/libvirt_nss_macs.c
+++ b/tools/nss/libvirt_nss_macs.c
@@ -134,6 +134,10 @@ findMACs(const char *file,
}
tok = json_tokener_new();
+ if (!tok) {
+ ERROR("failed to create JSON tokener");
+ goto cleanup;
+ }
json_tokener_set_flags(tok, jsonflags);
do {
@@ -162,7 +166,8 @@ findMACs(const char *file,
cleanup:
json_object_put(jobj);
- json_tokener_free(tok);
+ if (tok)
+ json_tokener_free(tok);
if (ret != 0) {
for (i = 0; i < *nmacs; i++) {
char *mac = (*macs)[i];
--
2.47.0
2 weeks, 5 days
Release of libvirt-10.9.0
by Jiri Denemark
The 10.9.0 release of both libvirt and libvirt-python is tagged and
signed tarballs are available at
https://download.libvirt.org/
https://download.libvirt.org/python/
Thanks everybody who helped with this release by sending patches,
reviewing, testing, or providing feedback. Your work is greatly
appreciated.
* New features
* qemu: zero block detection for non-shared-storage migration
Users can now request that all-zero blocks are not transferred when migrating
non-shared disk data without actually enabling zero detection on the disk
itself. This allows sparsifying images during migration where the source
has no access to the allocation state of blocks at the cost of CPU overhead.
This feature is available via the ``--migrate-disks-detect-zeroes`` option
for ``virsh migrate`` or ``VIR_MIGRATE_PARAM_MIGRATE_DISKS_DETECT_ZEROES``
migration parameter. See the documentation for caveats.
* Improvements
* qemu: internal snapshot improvements
The qemu internal snapshot handling code was updated to use modern commands
which avoid the problems the old ones had, preventing use of internal
snapshots on VMs with UEFI NVRAM. Internal snapshots of VMs using UEFI are
now possible provided that the NVRAM is in ``qcow2`` format.
The new code also allows better control when deleting snapshots. To prevent
possible regressions no strict checking is done, but in case inconsistent
state is encountered a log message is added::
warning : qemuSnapshotActiveInternalDeleteGetDevices:3841 : inconsistent internal snapshot state (deletion): VM='snap' snapshot='1727959843' missing='vda ' unexpected='' extra=''
Users are encouraged to report any occurence of the above message along
with steps they took to the upstream tracker.
* qemu: improve documentation of image format settings
The documentation of the various ``*_image_format`` settings in ``qemu.conf``
imply they can only be used to control compression of the image. The
documentation has been improved to clarify the settings describe the
representation of guest memory blocks on disk, which includes compression
among other possible layouts.
* Report CPU model blockers in domain capabilities
When a CPU model is reported as usable='no' an additional
``<blockers model='...'>`` element is added for that CPU model listing
features required by the CPU model, but not supported on the host.
Enjoy.
Jirka
3 weeks, 1 day