Re: [PATCH v2 02/10] qom: validate ID format when creating objects

2026-05-11 Thread Daniel P . Berrangé
On Mon, May 11, 2026 at 12:35:57PM +0200, Philippe Mathieu-Daudé wrote:
> On 8/5/26 13:24, Daniel P. Berrangé wrote:
> > The object_new_with_props/propv methods failed to validate the ID string
> > format, thus diverging from user_creatable_add_type.
> > 
> > Signed-off-by: Daniel P. Berrangé 
> > ---
> >   qom/object.c | 9 +
> >   1 file changed, 9 insertions(+)
> > 
> > diff --git a/qom/object.c b/qom/object.c
> > index 9c391071fb..62d2f0486a 100644
> > --- a/qom/object.c
> > +++ b/qom/object.c
> > @@ -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
> > @@ -764,6 +766,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;
> > +}
> 
> Use a common object_identifier_is_well_formed() helper?

At the end of this series, the only other use of id_wellformed in
qom/object_interfaces.c is removed, so there is no need for an
extracted helper method IMHO

> 
> > +
> >   klass = object_class_by_name(typename);
> >   if (!klass) {
> >   error_setg(errp, "invalid object type: %s", typename);
> 

With regards,
Daniel
-- 
|: https://berrange.com   ~~https://hachyderm.io/@berrange :|
|: https://libvirt.org  ~~  https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~https://fstop138.berrange.com :|




Re: [PATCH v2 02/10] qom: validate ID format when creating objects

2026-05-11 Thread Philippe Mathieu-Daudé

On 11/5/26 12:35, Philippe Mathieu-Daudé wrote:

On 8/5/26 13:24, Daniel P. Berrangé wrote:

The object_new_with_props/propv methods failed to validate the ID string
format, thus diverging from user_creatable_add_type.

Signed-off-by: Daniel P. Berrangé 
---
  qom/object.c | 9 +
  1 file changed, 9 insertions(+)

diff --git a/qom/object.c b/qom/object.c
index 9c391071fb..62d2f0486a 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -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
@@ -764,6 +766,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;
+    }


Use a common object_identifier_is_well_formed() helper?


I see the last patch of this series remove the duplication, so:

Reviewed-by: Philippe Mathieu-Daudé 




Re: [PATCH v2 02/10] qom: validate ID format when creating objects

2026-05-11 Thread Philippe Mathieu-Daudé

On 8/5/26 13:24, Daniel P. Berrangé wrote:

The object_new_with_props/propv methods failed to validate the ID string
format, thus diverging from user_creatable_add_type.

Signed-off-by: Daniel P. Berrangé 
---
  qom/object.c | 9 +
  1 file changed, 9 insertions(+)

diff --git a/qom/object.c b/qom/object.c
index 9c391071fb..62d2f0486a 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -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

@@ -764,6 +766,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;
+}


Use a common object_identifier_is_well_formed() helper?


+
  klass = object_class_by_name(typename);
  if (!klass) {
  error_setg(errp, "invalid object type: %s", typename);





[PATCH v2 02/10] qom: validate ID format when creating objects

2026-05-08 Thread Daniel P . Berrangé
The object_new_with_props/propv methods failed to validate the ID string
format, thus diverging from user_creatable_add_type.

Signed-off-by: Daniel P. Berrangé 
---
 qom/object.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/qom/object.c b/qom/object.c
index 9c391071fb..62d2f0486a 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -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
@@ -764,6 +766,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);
-- 
2.54.0