qom: validate ID format when creating objects
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>
Daniel P. Berrangé committed
Apr 17, 2026 at 15:36 UTC
ab67e622d0e33a6cf3d05737c4ff0bc873e413d9
1 file changed
+9
qom/object.c
+9
@@ -24,6 +24,8 @@
24
#include "qapi/forward-visitor.h"
25
#include "qapi/qapi-builtin-visit.h"
26
#include "qobject/qjson.h"
27
+#include "qemu/id.h"
28
+#include "qapi/qmp/qerror.h"
29
#include "trace.h"
30
31
/* TODO: replace QObject with a simpler visitor to avoid a dependency
@@ -755,6 +757,13 @@ Object *object_new_with_propv(const char *typename,
757
ObjectClass *klass;
758
UserCreatable *uc;
759
760
+ if (id != NULL && !id_wellformed(id)) {
761
+ error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "id", "an identifier");
762
+ error_append_hint(errp, "Identifiers consist of letters, digits, "
763
+ "'-', '.', '_', starting with a letter.\n");
764
+ return NULL;
765
+ }
766
+
767
klass = object_class_by_name(typename);
768
if (!klass) {
769
error_setg(errp, "invalid object type: %s", typename);