[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 05/23] qom: Check for wellformed id in user_creatable_add_type()
From: |
Paolo Bonzini |
Subject: |
[PULL 05/23] qom: Check for wellformed id in user_creatable_add_type() |
Date: |
Sat, 6 Mar 2021 11:54:01 +0100 |
From: Kevin Wolf <kwolf@redhat.com>
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 8db1efd3) and QMP object-add
(since it was first introduced in commit cff8b2c6). 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 <kwolf@redhat.com>
Message-Id: <20210302171623.49709-1-kwolf@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
qom/object_interfaces.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
index 1e9ad6f08a..7661270b98 100644
--- a/qom/object_interfaces.c
+++ b/qom/object_interfaces.c
@@ -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"
@@ -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);
--
2.29.2
- [PULL 00/23] Misc patches for 2021-03-06, Paolo Bonzini, 2021/03/06
- [PULL 01/23] KVM: x86: do not fail if software breakpoint has already been removed, Paolo Bonzini, 2021/03/06
- [PULL 02/23] KVM: x86: deprecate -M kernel-irqchip=off except for -M isapc, Paolo Bonzini, 2021/03/06
- [PULL 03/23] qga-vss: Use dynamic linking for GLib, Paolo Bonzini, 2021/03/06
- [PULL 04/23] chardev: add nodelay option, Paolo Bonzini, 2021/03/06
- [PULL 05/23] qom: Check for wellformed id in user_creatable_add_type(),
Paolo Bonzini <=
- [PULL 06/23] vl.c: do not execute trace_init_backends() before daemonizing, Paolo Bonzini, 2021/03/06
- [PULL 07/23] accel: kvm: Fix memory waste under mismatch page size, Paolo Bonzini, 2021/03/06
- [PULL 10/23] elf_ops: correct loading of 32 bit PVH kernel, Paolo Bonzini, 2021/03/06
- [PULL 11/23] x86/pvh: extract only 4 bytes of start address for 32 bit kernels, Paolo Bonzini, 2021/03/06
- [PULL 13/23] scsi: Rename linux-specific SG_ERR codes to generic SCSI_HOST error codes, Paolo Bonzini, 2021/03/06
- [PULL 12/23] qemu-config: add error propagation to qemu_config_parse, Paolo Bonzini, 2021/03/06
- [PULL 15/23] scsi-generic: do not snoop the output of failed commands, Paolo Bonzini, 2021/03/06
- [PULL 16/23] scsi: inline sg_io_sense_from_errno() into the callers., Paolo Bonzini, 2021/03/06
- [PULL 20/23] meson: adjust timeouts for some slower tests, Paolo Bonzini, 2021/03/06
- [PULL 21/23] trace: fix "-trace file=...", Paolo Bonzini, 2021/03/06