Limit type names to alphanumerical and some few special characters
v3 cover Limit type names to alphanumerical and some few special characters
QOM names currently don't have any enforced naming rules. This can be problematic, e.g. when they are used on the command line for the "-device" option (where the comma is used to separate properties). To avoid that such problematic type names come in again, let's restrict the set of acceptable characters during the type registration.
First four patches are clean-ups related to comma and colons in type names, and the final patch introduces the check for valid names.
v3:
- Added Reviewed-bys to the first four patches
- Changed last patch to use strspn() as suggested by Daniel
v2:
- Include Markus' patches in the series
- Add patches to clean up colons in type names
- Add the check to type_register_internal() instead of type_new() so that we can disallow colons, too
- Only allow '+' in legacy names
Markus Armbruster (2):
docs/system/arm: Fix for rename of type "xlnx.bbram-ctrl"
hw: Replace anti-social QOM type names (again)
Thomas Huth (3):
memory: Remove "qemu:" prefix from the "qemu:ram-discard-manager" type
name
tests/unit/test-io-task: Rename "qemu:dummy" to avoid colon in the
name
qom/object: Limit type names to alphanumerical and some few special
characters
docs/system/arm/xlnx-versal-virt.rst | 4 +-- include/exec/memory.h | 2 +- include/hw/misc/xlnx-versal-cframe-reg.h | 2 +- include/hw/misc/xlnx-versal-cfu.h | 6 ++-- include/hw/misc/xlnx-versal-crl.h | 2 +- include/hw/nvram/xlnx-efuse.h | 2 +- include/hw/nvram/xlnx-versal-efuse.h | 4 +-- include/hw/nvram/xlnx-zynqmp-efuse.h | 2 +- qom/object.c | 41 ++++++++++++++++++++++++ tests/unit/test-io-task.c | 2 +- 10 files changed, 54 insertions(+), 13 deletions(-)
Signature · 1 line
2.42.0
PATCH v3 1/5 docs/system/arm: Fix for rename of type "xlnx.bbram-ctrl"
From: Markus Armbruster <[email protected]>
--- docs/system/arm/xlnx-versal-virt.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
docs/system/arm/xlnx-versal-virt.rst +1 -1
@@ -194,7 +194,7 @@ To use a different index value, N, from default of 0, add: .. code-block:: bash - -global xlnx,bbram-ctrl.drive-index=N + -global driver=xlnx.bbram-ctrl,property=drive-index,value=N eFUSE File Backend """"""""""""""""""
Signature · 1 line
2.42.0
Re: [PATCH v3 1/5] docs/system/arm: Fix for rename of type "xlnx.bbram-ctrl"
Quoted 8 lines · Thomas Huth
From: Markus Armbruster <[email protected]>
Fixes b65b4b7ae3c8 (xlnx-bbram: hw/nvram: Use dot in device type name)Signed-off-by Markus Armbruster <[email protected]>[thuth: Use longhand syntax to avoid problems with the "." in the name]Reviewed-by Peter Maydell <[email protected]>Signed-off-by Thomas Huth <[email protected]>
Alistair
Quoted 21 lines
--- docs/system/arm/xlnx-versal-virt.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)docs/system/arm/xlnx-versal-virt.rst +1
-2@@ -194,7 +194,7 @@ To use a different index value, N, from default of 0, add: .. code-block:: bash - -global xlnx,bbram-ctrl.drive-index=N + -global driver=xlnx.bbram-ctrl,property=drive-index,value=N eFUSE File Backend """""""""""""""""" --2.42.0
PATCH v3 2/5 hw: Replace anti-social QOM type names (again)
In reply to Thomas HuthFrom: Markus Armbruster <[email protected]>
QOM type names containing ',' result in awful UI. We got rid of them in v6.0.0 (commit e178113ff64 hw: Replace anti-social QOM type names). A few have crept back since:
xlnx,cframe-reg
xlnx,efuse
xlnx,pmc-efuse-cache
xlnx,versal-cfu-apb
xlnx,versal-cfu-fdro
xlnx,versal-cfu-sfr
xlnx,versal-crl
xlnx,versal-efuse
xlnx,zynqmp-efuse
These are all device types. They can't be plugged with -device / device_add, except for "xlnx,efuse" (I'm not sure that one is intentional).
They *can* be used with -device / device_add to request help. Usability is poor, though: you have to double the comma, like this:
$ qemu-system-aarch64 -device xlnx,,pmc-efuse-cache,help
They can also be used with -global, where you must *not* double the comma:
$ qemu-system-aarch64 -global xlnx,efuse.drive-index=2
Trap for the unwary.
"xlnx,efuse", "xlnx,versal-efuse", "xlnx,pmc-efuse-cache", "xlnx-zynqmp-efuse" are from v6.2.0, "xlnx,versal-crl" is from v7.1.0, and the remainder are new.
Rename them all to "xlnx-FOO", like commit e178113ff64 did.
--- docs/system/arm/xlnx-versal-virt.rst | 2 +- include/hw/misc/xlnx-versal-cframe-reg.h | 2 +- include/hw/misc/xlnx-versal-cfu.h | 6 +++--- include/hw/misc/xlnx-versal-crl.h | 2 +- include/hw/nvram/xlnx-efuse.h | 2 +- include/hw/nvram/xlnx-versal-efuse.h | 4 ++-- include/hw/nvram/xlnx-zynqmp-efuse.h | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-)
docs/system/arm/xlnx-versal-virt.rst +1 -1
@@ -212,7 +212,7 @@ To use a different index value, N, from default of 1, add: .. code-block:: bash - -global xlnx,efuse.drive-index=N + -global xlnx-efuse.drive-index=N .. warning:: In actual physical Versal, BBRAM and eFUSE contain sensitive data.
include/hw/misc/xlnx-versal-cframe-reg.h +1 -1
@@ -23,7 +23,7 @@#include "hw/misc/xlnx-versal-cfu.h" #include "qemu/fifo32.h" -#define TYPE_XLNX_VERSAL_CFRAME_REG "xlnx,cframe-reg" +#define TYPE_XLNX_VERSAL_CFRAME_REG "xlnx-cframe-reg" OBJECT_DECLARE_SIMPLE_TYPE(XlnxVersalCFrameReg, XLNX_VERSAL_CFRAME_REG)#define TYPE_XLNX_VERSAL_CFRAME_BCAST_REG "xlnx.cframe-bcast-reg"
include/hw/misc/xlnx-versal-cfu.h +3 -3
@@ -22,13 +22,13 @@#include "hw/misc/xlnx-cfi-if.h" #include "qemu/fifo32.h" -#define TYPE_XLNX_VERSAL_CFU_APB "xlnx,versal-cfu-apb" +#define TYPE_XLNX_VERSAL_CFU_APB "xlnx-versal-cfu-apb" OBJECT_DECLARE_SIMPLE_TYPE(XlnxVersalCFUAPB, XLNX_VERSAL_CFU_APB) -#define TYPE_XLNX_VERSAL_CFU_FDRO "xlnx,versal-cfu-fdro" +#define TYPE_XLNX_VERSAL_CFU_FDRO "xlnx-versal-cfu-fdro" OBJECT_DECLARE_SIMPLE_TYPE(XlnxVersalCFUFDRO, XLNX_VERSAL_CFU_FDRO) -#define TYPE_XLNX_VERSAL_CFU_SFR "xlnx,versal-cfu-sfr" +#define TYPE_XLNX_VERSAL_CFU_SFR "xlnx-versal-cfu-sfr" OBJECT_DECLARE_SIMPLE_TYPE(XlnxVersalCFUSFR, XLNX_VERSAL_CFU_SFR)REG32 (CFU_ISR ,0x0 )
include/hw/misc/xlnx-versal-crl.h +1 -1
@@ -13,7 +13,7 @@#include "hw/register.h" #include "target/arm/cpu.h" -#define TYPE_XLNX_VERSAL_CRL "xlnx,versal-crl" +#define TYPE_XLNX_VERSAL_CRL "xlnx-versal-crl" OBJECT_DECLARE_SIMPLE_TYPE(XlnxVersalCRL, XLNX_VERSAL_CRL)REG32 (ERR_CTRL ,0x0 )
include/hw/nvram/xlnx-efuse.h +1 -1
@@ -30,7 +30,7 @@#include "sysemu/block-backend.h" #include "hw/qdev-core.h" -#define TYPE_XLNX_EFUSE "xlnx,efuse" +#define TYPE_XLNX_EFUSE "xlnx-efuse"OBJECT_DECLARE_SIMPLE_TYPE (XlnxEFuse,XLNX_EFUSE );struct XlnxEFuse {
include/hw/nvram/xlnx-versal-efuse.h +2 -2
@@ -29,8 +29,8 @@#define XLNX_VERSAL_EFUSE_CTRL_R_MAX ((0x100 / 4) + 1) -#define TYPE_XLNX_VERSAL_EFUSE_CTRL "xlnx,versal-efuse" -#define TYPE_XLNX_VERSAL_EFUSE_CACHE "xlnx,pmc-efuse-cache" +#define TYPE_XLNX_VERSAL_EFUSE_CTRL "xlnx-versal-efuse" +#define TYPE_XLNX_VERSAL_EFUSE_CACHE "xlnx-pmc-efuse-cache"OBJECT_DECLARE_SIMPLE_TYPE (XlnxVersalEFuseCtrl,XLNX_VERSAL_EFUSE_CTRL );OBJECT_DECLARE_SIMPLE_TYPE (XlnxVersalEFuseCache,XLNX_VERSAL_EFUSE_CACHE );
include/hw/nvram/xlnx-zynqmp-efuse.h +1 -1
@@ -29,7 +29,7 @@#define XLNX_ZYNQMP_EFUSE_R_MAX ((0x10fc / 4) + 1) -#define TYPE_XLNX_ZYNQMP_EFUSE "xlnx,zynqmp-efuse" +#define TYPE_XLNX_ZYNQMP_EFUSE "xlnx-zynqmp-efuse"OBJECT_DECLARE_SIMPLE_TYPE (XlnxZynqMPEFuse,XLNX_ZYNQMP_EFUSE );struct XlnxZynqMPEFuse {
Signature · 1 line
2.42.0
Re: [PATCH v3 2/5] hw: Replace anti-social QOM type names (again)
Quoted 37 lines · Thomas Huth
From: Markus Armbruster <[email protected]>
QOM type names containing ',' result in awful UI. We got rid of them in v6.0.0 (commit
e178113ff64hw: Replace anti-social QOM type names). A few have crept back since:xlnx,cframe-reg
xlnx,efuse
xlnx,pmc-efuse-cache
xlnx,versal-cfu-apb
xlnx,versal-cfu-fdro
xlnx,versal-cfu-sfr
xlnx,versal-crl
xlnx,versal-efuse
xlnx,zynqmp-efuseThese are all device types. They can't be plugged with -device /
device_add, except for "xlnx,efuse" (I'm not sure that one is intentional).They *can* be used with -device /
device_addto request help. Usability is poor, though: you have to double the comma, like this:$ qemu-system-aarch64 -device xlnx,,pmc-efuse-cache,helpThey can also be used with -global, where you must *not* double the comma:
$ qemu-system-aarch64 -global xlnx,efuse.drive-index=2Trap for the unwary.
"xlnx,efuse", "xlnx,versal-efuse", "xlnx,pmc-efuse-cache", "xlnx-zynqmp-efuse" are from v6.2.0, "xlnx,versal-crl" is from v7.1.0, and the remainder are new.
Quoted 7 lines
Rename them all to "xlnx-FOO", like commit
e178113ff64did.Reported-by Thomas Huth <[email protected]>Signed-off-by Markus Armbruster <[email protected]>Reviewed-by Thomas Huth <[email protected]>Reviewed-by Francisco Iglesias <[email protected]>Signed-off-by Thomas Huth <[email protected]>
Alistair
Quoted 115 lines
--- docs/system/arm/xlnx-versal-virt.rst | 2 +- include/hw/misc/xlnx-versal-cframe-reg.h | 2 +- include/hw/misc/xlnx-versal-cfu.h | 6 +++--- include/hw/misc/xlnx-versal-crl.h | 2 +- include/hw/nvram/xlnx-efuse.h | 2 +- include/hw/nvram/xlnx-versal-efuse.h | 4 ++-- include/hw/nvram/xlnx-zynqmp-efuse.h | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-)docs/system/arm/xlnx-versal-virt.rst +1
-1@@ -212,7 +212,7 @@ To use a different index value, N, from default of 1, add: .. code-block:: bash - -global xlnx,efuse.drive-index=N + -global xlnx-efuse.drive-index=N .. warning:: In actual physical Versal, BBRAM and eFUSE contain sensitive data.include/hw/misc/xlnx-versal-cframe-reg.h +1
-1@@ -23,7 +23,7 @@#include "hw/misc/xlnx-versal-cfu.h" #include "qemu/fifo32.h" -#define TYPE_XLNX_VERSAL_CFRAME_REG "xlnx,cframe-reg" +#define TYPE_XLNX_VERSAL_CFRAME_REG "xlnx-cframe-reg" OBJECT_DECLARE_SIMPLE_TYPE(XlnxVersalCFrameReg, XLNX_VERSAL_CFRAME_REG)#define TYPE_XLNX_VERSAL_CFRAME_BCAST_REG "xlnx.cframe-bcast-reg"include/hw/misc/xlnx-versal-cfu.h +3
-3@@ -22,13 +22,13 @@#include "hw/misc/xlnx-cfi-if.h" #include "qemu/fifo32.h" -#define TYPE_XLNX_VERSAL_CFU_APB "xlnx,versal-cfu-apb" +#define TYPE_XLNX_VERSAL_CFU_APB "xlnx-versal-cfu-apb" OBJECT_DECLARE_SIMPLE_TYPE(XlnxVersalCFUAPB, XLNX_VERSAL_CFU_APB) -#define TYPE_XLNX_VERSAL_CFU_FDRO "xlnx,versal-cfu-fdro" +#define TYPE_XLNX_VERSAL_CFU_FDRO "xlnx-versal-cfu-fdro" OBJECT_DECLARE_SIMPLE_TYPE(XlnxVersalCFUFDRO, XLNX_VERSAL_CFU_FDRO) -#define TYPE_XLNX_VERSAL_CFU_SFR "xlnx,versal-cfu-sfr" +#define TYPE_XLNX_VERSAL_CFU_SFR "xlnx-versal-cfu-sfr" OBJECT_DECLARE_SIMPLE_TYPE(XlnxVersalCFUSFR, XLNX_VERSAL_CFU_SFR)REG32 (CFU_ISR ,0x0 )include/hw/misc/xlnx-versal-crl.h +1
-1@@ -13,7 +13,7 @@#include "hw/register.h" #include "target/arm/cpu.h" -#define TYPE_XLNX_VERSAL_CRL "xlnx,versal-crl" +#define TYPE_XLNX_VERSAL_CRL "xlnx-versal-crl" OBJECT_DECLARE_SIMPLE_TYPE(XlnxVersalCRL, XLNX_VERSAL_CRL)REG32 (ERR_CTRL ,0x0 )include/hw/nvram/xlnx-efuse.h +1
-1@@ -30,7 +30,7 @@#include "sysemu/block-backend.h" #include "hw/qdev-core.h" -#define TYPE_XLNX_EFUSE "xlnx,efuse" +#define TYPE_XLNX_EFUSE "xlnx-efuse"OBJECT_DECLARE_SIMPLE_TYPE (XlnxEFuse,XLNX_EFUSE );struct XlnxEFuse {include/hw/nvram/xlnx-versal-efuse.h +2
-2@@ -29,8 +29,8 @@#define XLNX_VERSAL_EFUSE_CTRL_R_MAX ((0x100 / 4) + 1) -#define TYPE_XLNX_VERSAL_EFUSE_CTRL "xlnx,versal-efuse" -#define TYPE_XLNX_VERSAL_EFUSE_CACHE "xlnx,pmc-efuse-cache" +#define TYPE_XLNX_VERSAL_EFUSE_CTRL "xlnx-versal-efuse" +#define TYPE_XLNX_VERSAL_EFUSE_CACHE "xlnx-pmc-efuse-cache"OBJECT_DECLARE_SIMPLE_TYPE (XlnxVersalEFuseCtrl,XLNX_VERSAL_EFUSE_CTRL );OBJECT_DECLARE_SIMPLE_TYPE (XlnxVersalEFuseCache,XLNX_VERSAL_EFUSE_CACHE );include/hw/nvram/xlnx-zynqmp-efuse.h +1
-2@@ -29,7 +29,7 @@#define XLNX_ZYNQMP_EFUSE_R_MAX ((0x10fc / 4) + 1) -#define TYPE_XLNX_ZYNQMP_EFUSE "xlnx,zynqmp-efuse" +#define TYPE_XLNX_ZYNQMP_EFUSE "xlnx-zynqmp-efuse"OBJECT_DECLARE_SIMPLE_TYPE (XlnxZynqMPEFuse,XLNX_ZYNQMP_EFUSE );struct XlnxZynqMPEFuse { --2.42.0
PATCH v3 3/5 memory: Remove "qemu:" prefix from the "qemu:ram-discard-manager" type name
In reply to Thomas HuthType names should not contain special characters like ":". Let's remove the whole prefix here since it does not really seem to be helpful to have such a prefix here. The type name is only used internally for an interface type, so the renaming should not affect the user interface or migration.
--- include/exec/memory.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/exec/memory.h +1 -1
@@ -43,7 +43,7 @@ typedef struct IOMMUMemoryRegionClass IOMMUMemoryRegionClass;DECLARE_OBJ_CHECKERS (IOMMUMemoryRegion, IOMMUMemoryRegionClass, IOMMU_MEMORY_REGION, TYPE_IOMMU_MEMORY_REGION) -#define TYPE_RAM_DISCARD_MANAGER "qemu:ram-discard-manager" +#define TYPE_RAM_DISCARD_MANAGER "ram-discard-manager"typedef struct RamDiscardManagerClass RamDiscardManagerClass ;typedef struct RamDiscardManager RamDiscardManager ; DECLARE_OBJ_CHECKERS(RamDiscardManager, RamDiscardManagerClass,
Signature · 1 line
2.42.0
Re: [PATCH v3 3/5] memory: Remove "qemu:" prefix from the "qemu:ram-discard-manager" type name
Quoted 10 lines · Thomas Huth
Type names should not contain special characters like ":". Let's remove the whole prefix here since it does not really seem to be helpful to have such a prefix here. The type name is only used internally for an interface type, so the renaming should not affect the user interface or migration.
Reviewed-by David Hildenbrand <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Thomas Huth <[email protected]>
Alistair
Quoted 21 lines
--- include/exec/memory.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/exec/memory.h +1
-2@@ -43,7 +43,7 @@ typedef struct IOMMUMemoryRegionClass IOMMUMemoryRegionClass;DECLARE_OBJ_CHECKERS (IOMMUMemoryRegion, IOMMUMemoryRegionClass, IOMMU_MEMORY_REGION, TYPE_IOMMU_MEMORY_REGION) -#define TYPE_RAM_DISCARD_MANAGER "qemu:ram-discard-manager" +#define TYPE_RAM_DISCARD_MANAGER "ram-discard-manager"typedef struct RamDiscardManagerClass RamDiscardManagerClass ;typedef struct RamDiscardManager RamDiscardManager ; DECLARE_OBJ_CHECKERS(RamDiscardManager, RamDiscardManagerClass, --2.42.0
PATCH v3 4/5 tests/unit/test-io-task: Rename "qemu:dummy" to avoid colon in the name
In reply to Thomas HuthType names should not contain special characters like ":" (so that they are easier to use with QAPI and other parts). We are going to forbid such names in an upcoming patch. Thus let's replace the ":" here with a "-".
--- tests/unit/test-io-task.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/unit/test-io-task.c +1 -1
@@ -25,7 +25,7 @@#include "qapi/error.h" #include "qemu/module.h" -#define TYPE_DUMMY "qemu:dummy" +#define TYPE_DUMMY "qemu-dummy"typedef struct DummyObject DummyObject ;typedef struct DummyObjectClass DummyObjectClass ;
Signature · 1 line
2.42.0
Re: [PATCH v3 4/5] tests/unit/test-io-task: Rename "qemu:dummy" to avoid colon in the name
Quoted 9 lines · Thomas Huth
Type names should not contain special characters like ":" (so that they are easier to use with QAPI and other parts). We are going to forbid such names in an upcoming patch. Thus let's replace the ":" here with a "-".
Reviewed-by Daniel P. Berrangé <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Thomas Huth <[email protected]>
Alistair
Quoted 21 lines
--- tests/unit/test-io-task.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/unit/test-io-task.c +1
-2@@ -25,7 +25,7 @@#include "qapi/error.h" #include "qemu/module.h" -#define TYPE_DUMMY "qemu:dummy" +#define TYPE_DUMMY "qemu-dummy"typedef struct DummyObject DummyObject ;typedef struct DummyObjectClass DummyObjectClass ; --2.42.0
PATCH v3 5/5 qom/object: Limit type names to alphanumerical and some few special characters
In reply to Thomas HuthQOM names currently don't have any enforced naming rules. This can be problematic, e.g. when they are used on the command line for the "-device" option (where the comma is used to separate properties). To avoid that such problematic type names come in again, let's restrict the set of acceptable characters during the type registration.
Ideally, we'd apply here the same rules as for QAPI, i.e. all type names should begin with a letter, and contain only ASCII letters, digits, hyphen, and underscore. However, we already have so many pre-existing types like:
486-x86_64-cpu
cfi.pflash01
power5+_v2.1-spapr-cpu-core
virt-2.6-machine
pc-i440fx-3.0-machine... so that we have to allow "." and "+" for now, too. While the dot is used in a lot of places, the "+" can fortunately be limited to two classes of legacy names ("power" and "Sun-UltraSparc" CPUs).
We also cannot enforce the rule that names must start with a letter yet, since there are lot of types that start with a digit. Still, at least limiting the first characters to the alphanumerical range should be way better than nothing.
--- qom/object.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
qom/object.c +41 -0
@@ -138,9 +138,50 @@ static TypeImpl *type_new(const TypeInfo *info)return ti; } +static bool type_name_is_valid (const char *name) +{ +const int slen =strlen (name); +int plen; + +g_assert (slen >1 ); + +/* +* Ideally, the name should start with a letter - however, we've got +* too many names starting with a digit already, so allow digits here, +* too (except '0' which is not used yet) +*/ +if (!g_ascii_isalnum (name[0 ]) || name[0 ] =='0' ) { +return false; + } + + plen =strspn (name,"abcdefghijklmnopqrstuvwxyz" +"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +"0123456789-_." ); + +/* Allow some legacy names with '+' in it for compatibility reasons */ +if (name[plen] =='+' ) { +if (plen ==6 &&g_str_has_prefix (name,"power" )) { +/* Allow "power5+" and "power7+" CPU names*/ +return true; + } +if (plen >=17 &&g_str_has_prefix (name,"Sun-UltraSparc-I" )) { +/* Allow "Sun-UltraSparc-IV+" and "Sun-UltraSparc-IIIi+" */ +return true; + } + } + +return plen == slen; +} +static TypeImpl *type_register_internal (const TypeInfo *info) {TypeImpl *ti; + +if (!type_name_is_valid (info->name)) { +fprintf (stderr,"Registering '%s' with illegal type name\n" , info->name); +abort (); + } + ti =type_new (info);type_table_add (ti);
Signature · 1 line
2.42.0
Re: [PATCH v3 5/5] qom/object: Limit type names to alphanumerical and some few special characters
Quoted 71 lines · Thomas Huth
QOM names currently don't have any enforced naming rules. This can be problematic, e.g. when they are used on the command line for the "-device" option (where the comma is used to separate properties). To avoid that such problematic type names come in again, let's restrict the set of acceptable characters during the type registration.
Ideally, we'd apply here the same rules as for QAPI, i.e. all type names should begin with a letter, and contain only ASCII letters, digits, hyphen, and underscore. However, we already have so many pre-existing types like:
486-x86_64-cpu cfi.pflash01 power5+_v2.1-spapr-cpu-core virt-2.6-machine pc-i440fx-3.0-machine... so that we have to allow "." and "+" for now, too. While the dot is used in a lot of places, the "+" can fortunately be limited to two classes of legacy names ("power" and "Sun-UltraSparc" CPUs).
We also cannot enforce the rule that names must start with a letter yet, since there are lot of types that start with a digit. Still, at least limiting the first characters to the alphanumerical range should be way better than nothing.
Signed-off-by Thomas Huth <[email protected]>--- qom/object.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)qom/object.c +31
-0@@ -138,9 +138,50 @@ static TypeImpl *type_new(const TypeInfo *info)return ti; } +static bool type_name_is_valid (const char *name) +{ +const int slen =strlen (name); +int plen; + +g_assert (slen >1 ); + +/* +* Ideally, the name should start with a letter - however, we've got +* too many names starting with a digit already, so allow digits here, +* too (except '0' which is not used yet) +*/ +if (!g_ascii_isalnum (name[0 ]) || name[0 ] =='0' ) { +return false; + } + + plen =strspn (name,"abcdefghijklmnopqrstuvwxyz" +"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +"0123456789-_." ); + +/* Allow some legacy names with '+' in it for compatibility reasons */ +if (name[plen] =='+' ) { +if (plen ==6 &&g_str_has_prefix (name,"power" )) { +/* Allow "power5+" and "power7+" CPU names*/ +return true; + } +if (plen >=17 &&g_str_has_prefix (name,"Sun-UltraSparc-I" )) { +/* Allow "Sun-UltraSparc-IV+" and "Sun-UltraSparc-IIIi+" */ +return true; + } + }
qom/object.c static TypeImpl *type_new(const TypeInfo *info) · line 181
Quoted 10 lines
qom/object.c +7
-0+ +return plen == slen; +} +static TypeImpl *type_register_internal (const TypeInfo *info) {TypeImpl *ti; + +if (!type_name_is_valid (info->name)) { +fprintf (stderr,"Registering '%s' with illegal type name\n" , info->name);
Shouldn't we use error_report() instead of fprintf()? Regardless,
Quoted 6 lines
qom/object.c +3
-0+abort (); + } + ti =type_new (info);type_table_add (ti);
Re: [PATCH v3 5/5] qom/object: Limit type names to alphanumerical and some few special characters
Quoted 76 lines · Philippe Mathieu-Daudé
Quoted 75 lines · Thomas Huth
QOM names currently don't have any enforced naming rules. This can be problematic, e.g. when they are used on the command line for the "-device" option (where the comma is used to separate properties). To avoid that such problematic type names come in again, let's restrict the set of acceptable characters during the type registration.
Ideally, we'd apply here the same rules as for QAPI, i.e. all type names should begin with a letter, and contain only ASCII letters, digits, hyphen, and underscore. However, we already have so many pre-existing types like:
486-x86_64-cpu
cfi.pflash01
power5+_v2.1-spapr-cpu-core
virt-2.6-machine
pc-i440fx-3.0-machine... so that we have to allow "." and "+" for now, too. While the dot is used in a lot of places, the "+" can fortunately be limited to two classes of legacy names ("power" and "Sun-UltraSparc" CPUs).
We also cannot enforce the rule that names must start with a letter yet, since there are lot of types that start with a digit. Still, at least limiting the first characters to the alphanumerical range should be way better than nothing.
Signed-off-by Thomas Huth <[email protected]>---
qom/object.c| 41 +++++++++++++++++++++++++++++++++++++++++1 file changed, 41 insertions(+)qom/object.c +35
-0@@ -138,9 +138,50 @@ static TypeImpl *type_new(const TypeInfo *info) return ti; } +static bool type_name_is_valid (const char *name) +{ + const int slen = strlen(name); + int plen; + + g_assert(slen > 1); + + /* + * Ideally, the name should start with a letter - however, we've got + * too many names starting with a digit already, so allow digits here, + * too (except '0' which is not used yet) + */ + if (!g_ascii_isalnum(name[0]) || name[0] == '0') { + return false; + } + + plen = strspn(name, "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "0123456789-_."); + + /* Allow some legacy names with '+' in it for compatibility reasons */ + if (name[plen] == '+') { + if (plen == 6 && g_str_has_prefix(name, "power")) { + /* Allow "power5+" and "power7+" CPU names*/ + return true; + } + if (plen >= 17 && g_str_has_prefix(name, "Sun-UltraSparc-I")) { + /* Allow "Sun-UltraSparc-IV+" and "Sun-UltraSparc-IIIi+" */ + return true; + } + } + + return plen == slen; +} + static TypeImpl *type_register_internal(const TypeInfo *info)
Quoted 8 lines
qom/object.c static TypeImpl *type_new(const TypeInfo *info)
Quoted 6 lines
qom/object.c +3
-0{ TypeImpl *ti; + + if (!type_name_is_valid(info->name)) { + fprintf(stderr, "Registering '%s' with illegal type name\n", info->name);Shouldn't we use
error_report()instead offprintf()? Regardless,
It doesn't work here yet - the type registration happens so early that we cannot use error_report() here yet.
Quoted 1 line
Reviewed-by Philippe Mathieu-Daudé <[email protected]>
Thanks!
Thomas
Re: [PATCH v3 5/5] qom/object: Limit type names to alphanumerical and some few special characters
In reply to Thomas HuthQuoted 23 lines · Thomas Huth
QOM names currently don't have any enforced naming rules. This can be problematic, e.g. when they are used on the command line for the "-device" option (where the comma is used to separate properties). To avoid that such problematic type names come in again, let's restrict the set of acceptable characters during the type registration.
Ideally, we'd apply here the same rules as for QAPI, i.e. all type names should begin with a letter, and contain only ASCII letters, digits, hyphen, and underscore. However, we already have so many pre-existing types like:
486-x86_64-cpu cfi.pflash01 power5+_v2.1-spapr-cpu-core virt-2.6-machine pc-i440fx-3.0-machine... so that we have to allow "." and "+" for now, too. While the dot is used in a lot of places, the "+" can fortunately be limited to two classes of legacy names ("power" and "Sun-UltraSparc" CPUs).
Quoted 6 lines
We also cannot enforce the rule that names must start with a letter yet, since there are lot of types that start with a digit. Still, at least limiting the first characters to the alphanumerical range should be way better than nothing.
Signed-off-by Thomas Huth <[email protected]>
Alistair
Quoted 63 lines
--- qom/object.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)qom/object.c +41
-1@@ -138,9 +138,50 @@ static TypeImpl *type_new(const TypeInfo *info)return ti; } +static bool type_name_is_valid (const char *name) +{ +const int slen =strlen (name); +int plen; + +g_assert (slen >1 ); + +/* +* Ideally, the name should start with a letter - however, we've got +* too many names starting with a digit already, so allow digits here, +* too (except '0' which is not used yet) +*/ +if (!g_ascii_isalnum (name[0 ]) || name[0 ] =='0' ) { +return false; + } + + plen =strspn (name,"abcdefghijklmnopqrstuvwxyz" +"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +"0123456789-_." ); + +/* Allow some legacy names with '+' in it for compatibility reasons */ +if (name[plen] =='+' ) { +if (plen ==6 &&g_str_has_prefix (name,"power" )) { +/* Allow "power5+" and "power7+" CPU names*/ +return true; + } +if (plen >=17 &&g_str_has_prefix (name,"Sun-UltraSparc-I" )) { +/* Allow "Sun-UltraSparc-IV+" and "Sun-UltraSparc-IIIi+" */ +return true; + } + } + +return plen == slen; +} +static TypeImpl *type_register_internal (const TypeInfo *info) {TypeImpl *ti; + +if (!type_name_is_valid (info->name)) { +fprintf (stderr,"Registering '%s' with illegal type name\n" , info->name); +abort (); + } + ti =type_new (info);type_table_add (ti); --2.42.0