Skip to content

Commit

Permalink
qom: Check for wellformed id in user_creatable_add_type()
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
kevmw authored and bonzini committed Mar 6, 2021
1 parent a9b1315 commit 0bd5a2e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions qom/object_interfaces.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "qapi/qobject-input-visitor.h"
#include "qom/object_interfaces.h"
#include "qemu/help_option.h"
#include "qemu/id.h"
#include "qemu/module.h"
#include "qemu/option.h"
#include "qapi/opts-visitor.h"
Expand Down Expand Up @@ -41,11 +42,19 @@ Object *user_creatable_add_type(const char *type, const char *id,
const QDict *qdict,
Visitor *v, Error **errp)
{
ERRP_GUARD();
Object *obj;
ObjectClass *klass;
const QDictEntry *e;
Error *local_err = NULL;

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(type);
if (!klass) {
error_setg(errp, "invalid object type: %s", type);
Expand Down

0 comments on commit 0bd5a2e

Please sign in to comment.