[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] i386: Fix GCC warning with snprintf when HAX is enabled
From: |
Richard Henderson |
Subject: |
Re: [PATCH] i386: Fix GCC warning with snprintf when HAX is enabled |
Date: |
Sun, 1 Mar 2020 10:36:46 -0800 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 |
On 3/1/20 8:35 AM, Julio Faracco wrote:
> When HAX is enabled (--enable-hax), GCC 9.2.1 reports issues with
> snprintf(). This commit is checking if snprintf returns an error. This
> is a simple way to avoid this warnings.
>
> For more details, one example of warning:
> CC i386-softmmu/target/i386/hax-posix.o
> qemu/target/i386/hax-posix.c: In function ‘hax_host_open_vm’:
> qemu/target/i386/hax-posix.c:124:56: error: ‘%02d’ directive output may be
> truncated writing between 2 and 11 bytes into a region of size 3
> [-Werror=format-truncation=]
> 124 | snprintf(name, sizeof HAX_VM_DEVFS, "/dev/hax_vm/vm%02d", vm_id);
> | ^~~~
> qemu/target/i386/hax-posix.c:124:41: note: directive argument in the range
> [-2147483648, 64]
The code bounds vm_id from the top (64) but not the bottom. The compiler has
(correctly) determined that negative values will overflow your buffer.
I suggest either an assert vs negative values as a local change, or to change
the type of vm_id (universally, if possible) to an unsigned type.
r~