[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH] fix virParseVersionString with linux 3.0



2011/7/1 Scott Moser <smoser ubuntu com>:
> linux 3.0 has no micro version number, and that is causing problems
> for virParseVersionString.  The patch below should allow for:
>  major
>  major.minor
>  major.minor.micro
>
> If major or minor are not present they just default to zero.
> We found this in Ubuntu (https://bugs.launchpad.net/bugs/802977)
>
> diff --git a/src/util/util.c b/src/util/util.c
> index 463d2b8..01848a1 100644
> --- a/src/util/util.c
> +++ b/src/util/util.c
> @@ -1598,17 +1598,17 @@ virParseNumber(const char **str)
>  int
>  virParseVersionString(const char *str, unsigned long *version)
>  {
> -    unsigned int major, minor, micro;
> +    unsigned int major, minor=0, micro=0;
>     char *tmp;
>
> -    if (virStrToLong_ui(str, &tmp, 10, &major) < 0 || *tmp != '.')
> +    if (virStrToLong_ui(str, &tmp, 10, &major) < 0)
>         return -1;
>
> -    if (virStrToLong_ui(tmp + 1, &tmp, 10, &minor) < 0 || *tmp != '.')
> -        return -1;
> +    if ((*tmp == '.') && virStrToLong_ui(tmp + 1, &tmp, 10, &minor) < 0)
> +            return -1;
>
> -    if (virStrToLong_ui(tmp + 1, &tmp, 10, &micro) < 0)
> -        return -1;
> +    if ((*tmp == '.') && virStrToLong_ui(tmp + 1, &tmp, 10, &micro) < 0)
> +            return -1;
>
>     *version = 1000000 * major + 1000 * minor + micro;
>

Well, your patch fixes the problem, but virParseVersionString is used
in more places than just kernel version parsing, therefore I think it
relaxes parsing too much and we need a stricter approach for this.

-- 
Matthias Bolte
http://photron.blogspot.com


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]