Skip to content

Commit 0bd5a2e

Browse files
kevmwbonzini
authored andcommitted
qom: Check for wellformed id in user_creatable_add_type()
Most code paths for creating a user creatable object go through QemuOpts, which ensures that the provided 'id' option is actually a valid identifier. However, there are some code paths that don't go through QemuOpts: qemu-storage-daemon --object (since commit 8db1efd) and QMP object-add (since it was first introduced in commit cff8b2c). We need to have the same validity check for those, too. This adds the check and makes it print the same error message as QemuOpts on failure. Signed-off-by: Kevin Wolf <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent a9b1315 commit 0bd5a2e

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

qom/object_interfaces.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "qapi/qobject-input-visitor.h"
99
#include "qom/object_interfaces.h"
1010
#include "qemu/help_option.h"
11+
#include "qemu/id.h"
1112
#include "qemu/module.h"
1213
#include "qemu/option.h"
1314
#include "qapi/opts-visitor.h"
@@ -41,11 +42,19 @@ Object *user_creatable_add_type(const char *type, const char *id,
4142
const QDict *qdict,
4243
Visitor *v, Error **errp)
4344
{
45+
ERRP_GUARD();
4446
Object *obj;
4547
ObjectClass *klass;
4648
const QDictEntry *e;
4749
Error *local_err = NULL;
4850

51+
if (id != NULL && !id_wellformed(id)) {
52+
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "id", "an identifier");
53+
error_append_hint(errp, "Identifiers consist of letters, digits, "
54+
"'-', '.', '_', starting with a letter.\n");
55+
return NULL;
56+
}
57+
4958
klass = object_class_by_name(type);
5059
if (!klass) {
5160
error_setg(errp, "invalid object type: %s", type);

0 commit comments

Comments
 (0)