]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
qom: validate ID format when creating objects
authorDaniel P. Berrangé <berrange@redhat.com>
Fri, 17 Apr 2026 14:36:18 +0000 (15:36 +0100)
committerDaniel P. Berrangé <berrange@redhat.com>
Thu, 21 May 2026 11:39:54 +0000 (12:39 +0100)
The object_new_with_props/propv methods failed to validate the ID string
format, thus diverging from user_creatable_add_type.

Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
qom/object.c

index 4a15151c3b5110debea4f7f2cff6522edfffa481..08fc840f39a7ebf4e3fa0b4f6603eb4fc5c13808 100644 (file)
@@ -24,6 +24,8 @@
 #include "qapi/forward-visitor.h"
 #include "qapi/qapi-builtin-visit.h"
 #include "qobject/qjson.h"
+#include "qemu/id.h"
+#include "qapi/qmp/qerror.h"
 #include "trace.h"
 
 /* TODO: replace QObject with a simpler visitor to avoid a dependency
@@ -755,6 +757,13 @@ Object *object_new_with_propv(const char *typename,
     ObjectClass *klass;
     UserCreatable *uc;
 
+    if (id != NULL && !id_wellformed(id)) {
+        error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "id", "an identifier");
+        error_append_hint(errp, "Identifiers consist of letters, digits, "
+                          "'-', '.', '_', starting with a letter.\n");
+        return NULL;
+    }
+
     klass = object_class_by_name(typename);
     if (!klass) {
         error_setg(errp, "invalid object type: %s", typename);