]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: virTypedParamValidateType: Don't report unknown typed parameter type as '(null)'
authorPeter Krempa <pkrempa@redhat.com>
Wed, 22 Apr 2026 09:58:07 +0000 (11:58 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 14 May 2026 10:13:09 +0000 (12:13 +0200)
If the actual type of the typed parameter is an invalid number the type
checker would still attempt to convert it to a string resulting in an
attempt to print a NULL string. libc saves us from the crash but the
error message is still wrong. Fix it.

Fixes: 54dd75fd97339dd49a54554e9327e5680c72132b
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/util/virtypedparam.c

index 0b40c14f902257edd7091efea82bb2c565edada8..6cfdd3276d22a81ec313818cb1ee05a56da633a5 100644 (file)
@@ -56,6 +56,13 @@ int
 virTypedParamValidateType(virTypedParameterPtr param,
                           unsigned int expected_type)
 {
+    if (param->type <= 0 || param->type >= VIR_TYPED_PARAM_LAST) {
+        virReportError(VIR_ERR_INVALID_ARG,
+                       _("unknown type ('%1$d') of parameter '%2$s'"),
+                       param->type, param->field);
+        return -1;
+    }
+
     if (param->type != expected_type) {
         virReportError(VIR_ERR_INVALID_ARG,
                        _("invalid type '%1$s' for parameter '%2$s', expected '%3$s'"),