Re: [PATCH kvmtool 2/3] virtio: fix warning on strncpy

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

 



Hi Andre,

On Mon, Jan 28, 2019 at 11:08:57AM +0000, Andre Przywara wrote:
> On Mon, 28 Jan 2019 10:17:03 +0000
> Andre Przywara <andre.przywara@xxxxxxx> wrote:
[...]
> > -		strncpy(ifr.ifr_name, ndev->tap_name, sizeof(ndev->tap_name));
> > +		strncpy(ifr.ifr_name, ndev->tap_name, sizeof(ifr.ifr_name));
> 
> Isn't that the old strncpy trap, where we could end up with an
> unterminated string? So it should either be "sizeof() - 1" or we use
> strlcpy(), which would just require to #include "kvm/strbuf.h".
> It seems that this should not happen in this particular case, but still.
> 
> I see that we have more strncpy's and friends with the same problems
> around, so this fix is still valid, especially if it appeases GCC 8. So
> my R-B: still stands, but I think we should fix those as well. I
> remember there was once a series to tackle this ...
> 

It is in fact an issue, but since ndev->tap_name came from the user I
didn't sweat it too much (it's still an issue if people do automation on
top of kvmtool).

In the end, the proper way to fix this is to use strlcpy, strscpy or
snprintf and always check the return value for truncation.

Regards,

Anisse



[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