Re: [PATCH kvmtool v2 3/3] kvmtool: 9p: fix overapping snprintf

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

 



On Mon,  4 Feb 2019 10:59:44 +0100
Anisse Astier <aastier@xxxxxxxxxx> wrote:

> GCC 8.2 gives this warning:
> 
> virtio/9p.c: In function ‘virtio_p9_create’:
> virtio/9p.c:335:21: error: passing argument 1 to restrict-qualified parameter aliases with argument 4 [-Werror=restrict]
>   ret = snprintf(dfid->path, size, "%s/%s", dfid->path, name);
>                  ~~~~^~~~~~                 ~~~~~~~~~~
> 
> Fix it by allocating a temporary string with dfid->path content instead
> of overwriting it in-place, which is limited in glibc snprintf with the
> __restrict qualifier.
> 
> Signed-off-by: Anisse Astier <aastier@xxxxxxxxxx>

Reviewed-by: Andre Przywara <andre.przywara@xxxxxxx>

Cheers,
Andre

> ---
>  virtio/9p.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/virtio/9p.c b/virtio/9p.c
> index 6bae403..ac70dbc 100644
> --- a/virtio/9p.c
> +++ b/virtio/9p.c
> @@ -322,6 +322,7 @@ static void virtio_p9_create(struct p9_dev *p9dev,
>  	struct p9_qid qid;
>  	struct p9_fid *dfid;
>  	char full_path[PATH_MAX];
> +	char *tmp_path;
>  	u32 dfid_val, flags, mode, gid;
>  
>  	virtio_p9_pdu_readf(pdu, "dsddd", &dfid_val,
> @@ -332,7 +333,13 @@ static void virtio_p9_create(struct p9_dev *p9dev,
>  		goto err_out;
>  
>  	size = sizeof(dfid->abs_path) - (dfid->path - dfid->abs_path);
> -	ret = snprintf(dfid->path, size, "%s/%s", dfid->path, name);
> +
> +	tmp_path = strdup(dfid->path);
> +	if (!tmp_path)
> +		goto err_out;
> +
> +	ret = snprintf(dfid->path, size, "%s/%s", tmp_path, name);
> +	free(tmp_path);
>  	if (ret >= (int)size) {
>  		errno = ENAMETOOLONG;
>  		if (size > 0)




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux