Re: [virt-viewer PATCH v2 2/3] Fix warning about missing nul terminator with strncpy

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

 



Reviewed-by: Christophe Fergeau <cfergeau@xxxxxxxxxx>

On Tue, Feb 19, 2019 at 03:00:10PM +0000, Daniel P. Berrangé wrote:
> We're intentionally not copying the nul terminator, but gcc rightly
> worries that this could be a coding mistake
> 
> windows-cmdline-wrapper.c: In function 'main':
> windows-cmdline-wrapper.c:65:9: warning: 'strncpy' output truncated before terminating nul copying 3 bytes from a string of the same length [-Wstringop-truncation]
>          strncpy(name + len - 3, "exe", 3);
>          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> Use memcpy() to make it clear we don't care about the nul terminator in
> the data we're copying.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
> ---
>  src/windows-cmdline-wrapper.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/windows-cmdline-wrapper.c b/src/windows-cmdline-wrapper.c
> index 704e2d7..7299ab2 100644
> --- a/src/windows-cmdline-wrapper.c
> +++ b/src/windows-cmdline-wrapper.c
> @@ -62,7 +62,7 @@ int main(int argc, char *argv[])
>          // We expect our helper to end with .com
>          assert(strncmp(name + len - 3, "com", 4) == 0);
>          // replace .com with .exe
> -        strncpy(name + len - 3, "exe", 3);
> +        memcpy(name + len - 3, "exe", 3);
>      }
>  
>      si.cb = sizeof(si);
> -- 
> 2.20.1
> 
> _______________________________________________
> virt-tools-list mailing list
> virt-tools-list@xxxxxxxxxx
> https://www.redhat.com/mailman/listinfo/virt-tools-list

Attachment: signature.asc
Description: PGP signature

_______________________________________________
virt-tools-list mailing list
virt-tools-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/virt-tools-list

[Index of Archives]     [Linux Virtualization]     [KVM Development]     [CentOS Virtualization]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]     [Video 4 Linux]

  Powered by Linux