|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [xen staging] libxl: simplify and correct domain ID and CPU pool ID parsing
commit 1310e78c472f1ee4345d2b0e27675e4175303d52
Author: Jan Beulich <jbeulich@xxxxxxxx>
AuthorDate: Tue Nov 24 08:30:29 2026 +0100
Commit: Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Tue Nov 24 08:30:29 2026 +0100
libxl: simplify and correct domain ID and CPU pool ID parsing
strtoul(), with a radix of 10, already guarantees that the string parsed
consists of just digits (and leading whitespace). No need to do that check
in advance. All which needs doing is a check for a leading digit, to
exclude the case of leading whitespace.
This in particular avoids a domain ID argument of "" to be mis-treated as
a reference to Dom0.
While similar mis-treatment isn't present there, do the same
simplification also in the adjacent qualifier_to_id().
Fixes: ef496b81f033 ("libxl: postpone backend name resolution")
Reported-by: Msd <msd-xenproject.org@xxxxxx>
Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
Reviewed-by: Juergen Gross <jgross@xxxxxxxx>
Acked-by: Anthony PERARD <anthony.perard@xxxxxxxxxx>
---
tools/libs/light/libxl_utils.c | 35 ++++++++++++++---------------------
1 file changed, 14 insertions(+), 21 deletions(-)
diff --git a/tools/libs/light/libxl_utils.c b/tools/libs/light/libxl_utils.c
index 5ae8935344..44e4118f66 100644
--- a/tools/libs/light/libxl_utils.c
+++ b/tools/libs/light/libxl_utils.c
@@ -91,16 +91,16 @@ int libxl_name_to_domid(libxl_ctx *ctx, const char *name,
int libxl_domain_qualifier_to_domid(libxl_ctx *ctx, const char *name,
uint32_t *domid)
{
- int i, rv;
- for (i=0; name[i]; i++) {
- if (!CTYPE(isdigit, name[i])) {
- goto nondigit_found;
- }
+ int rv;
+
+ if (CTYPE(isdigit, *name)) {
+ char *end;
+
+ *domid = strtoul(name, &end, 10);
+ if (end != name && !*end)
+ return 0;
}
- *domid = strtoul(name, NULL, 10);
- return 0;
- nondigit_found:
/* this could also check for uuids */
rv = libxl_name_to_domid(ctx, name, domid);
return rv;
@@ -108,22 +108,15 @@ int libxl_domain_qualifier_to_domid(libxl_ctx *ctx, const
char *name,
static int qualifier_to_id(const char *p, uint32_t *id_r)
{
- int i, alldigit;
+ if (CTYPE(isdigit, *p)) {
+ char *end;
- alldigit = 1;
- for (i = 0; p[i]; i++) {
- if (!isdigit((uint8_t)p[i])) {
- alldigit = 0;
- break;
- }
+ *id_r = strtoul(p, &end, 10);
+ if (end != p && !*end)
+ return 0;
}
- if (i > 0 && alldigit) {
- *id_r = strtoul(p, NULL, 10);
- return 0;
- } else {
- /* check here if it's a uuid and do proper conversion */
- }
+ /* check here if it's a uuid and do proper conversion */
return 1;
}
--
generated by git-patchbot for /home/xen/git/xen.git#staging
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |