On 16.06.2023 15:10, Roger Pau Monne wrote:
> --- a/tools/libs/light/libxl_cpuid.c
> +++ b/tools/libs/light/libxl_cpuid.c
> @@ -88,6 +88,66 @@ static struct xc_xend_cpuid 
> *cpuid_find_match(libxl_cpuid_policy *policy,
>      return *list + i;
>  }
>  
> +static int cpuid_add(libxl_cpuid_policy *policy, const struct cpuid_flags 
> *flag,
> +                     const char *val)
> +{
> +    struct xc_xend_cpuid *entry = cpuid_find_match(policy, flag->leaf,
> +                                                   flag->subleaf);
> +    unsigned long num;
> +    char flags[33], *resstr, *endptr;
> +    unsigned int i;
> +
> +    resstr = entry->policy[flag->reg - 1];
> +    num = strtoull(val, &endptr, 0);
> +    flags[flag->length] = 0;
> +    if (endptr != val) {
> +        /* if this was a valid number, write the binary form into the string 
> */
> +        for (i = 0; i < flag->length; i++) {
> +            flags[flag->length - 1 - i] = "01"[!!(num & (1 << i))];

I expect you've left this as is because you really only want to move code
here? At the very least the UB should be eliminated imo, by using 1u in
the shift. Even better might be "01"[(num >> i) & 1]. And of course using
strtoull() when num is unsigned long is a little fishy as well ...

Jan

Reply via email to