[pve-devel] applied: [PATCH cluster] use unsigned long for strtoul result

Wolfgang Bumiller w.bumiller at proxmox.com
Mon Mar 6 15:36:54 CET 2017


applied

On Fri, Mar 03, 2017 at 09:17:58AM +0100, Dominik Csapak wrote:
> strtoul gives back an unsigned long int, which may or may not be wider
> than a guint32 (depending on the platform)
> 
> when it is wider, the assignment would parse vmids bigger than 2^32 but
> truncate them, giving back an invalid vmid
> 
> Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
> ---
>  data/src/memdb.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/data/src/memdb.c b/data/src/memdb.c
> index e10aac4..56044b4 100644
> --- a/data/src/memdb.c
> +++ b/data/src/memdb.c
> @@ -210,19 +210,18 @@ name_is_vm_config(
>  	if (!name || name[0] < '1' || name[0] > '9')
>  		return FALSE;
>  
> -	
>  	char *end = NULL;
>  
>  	errno = 0; /* see man strtoul */
> -	
> -	guint32 vmid =  strtoul(name, &end, 10);
> +
> +	unsigned long int vmid = strtoul(name, &end, 10);
>  
>  	if (!end || end[0] != '.' || end[1] != 'c'|| end[2] != 'o' || end[3] != 'n' ||
> -	    end[4] != 'f' || end[5] != 0 || errno != 0)
> +	    end[4] != 'f' || end[5] != 0 || errno != 0 || vmid > G_MAXUINT32)
>  		return FALSE;
>  
>  	if (vmid_ret)
> -		*vmid_ret = vmid;
> +		*vmid_ret = (guint32)vmid;
>  
>  	return TRUE;
>  }
> -- 
> 2.1.4




More information about the pve-devel mailing list