mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-07-23 01:59:04 +00:00
tun: Use safe stlcpy instead of strcpy
Reading from NetDeviceEntry directly is not safe and may cause buffer overflow. Use stlcpy helper. Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org> Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
parent
bc002e8537
commit
369f366a36
1 changed files with 5 additions and 4 deletions
9
tun.c
9
tun.c
|
|
@ -7,6 +7,7 @@
|
|||
#include "crtools.h"
|
||||
#include "protobuf.h"
|
||||
#include "cr-show.h"
|
||||
#include "string.h"
|
||||
#include "files.h"
|
||||
#include "files-reg.h"
|
||||
#include "tun.h"
|
||||
|
|
@ -92,7 +93,7 @@ static int list_tun_link(NetDeviceEntry *nde)
|
|||
if (!tl)
|
||||
return -1;
|
||||
|
||||
strcpy(tl->name, nde->name);
|
||||
strlcpy(tl->name, nde->name, sizeof(tl->name));
|
||||
/*
|
||||
* Keep tun-flags not only for persistency fixup (see
|
||||
* commend below), but also for TUNSETIFF -- we must
|
||||
|
|
@ -123,7 +124,7 @@ static struct tun_link *__dump_tun_link_fd(int fd, char *name, unsigned flags)
|
|||
tl = xmalloc(sizeof(*tl));
|
||||
if (!tl)
|
||||
goto err;
|
||||
strcpy(tl->name, name);
|
||||
strlcpy(tl->name, name, sizeof(tl->name));
|
||||
|
||||
if (ioctl(fd, TUNGETVNETHDRSZ, &tl->dmp.vnethdr) < 0) {
|
||||
pr_perror("Can't dump vnethdr size for %s", name);
|
||||
|
|
@ -209,7 +210,7 @@ static int open_tun_dev(char *name, unsigned int idx, unsigned flags)
|
|||
}
|
||||
|
||||
memset(&ifr, 0, sizeof(ifr));
|
||||
strcpy(ifr.ifr_name, name);
|
||||
strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
||||
ifr.ifr_flags = flags;
|
||||
|
||||
if (ioctl(fd, TUNSETIFF, &ifr)) {
|
||||
|
|
@ -333,7 +334,7 @@ static int tunfile_open(struct file_desc *d)
|
|||
}
|
||||
|
||||
memset(&ifr, 0, sizeof(ifr));
|
||||
strcpy(ifr.ifr_name, tl->name);
|
||||
strlcpy(ifr.ifr_name, tl->name, sizeof(ifr.ifr_name));
|
||||
ifr.ifr_flags = tl->rst.flags;
|
||||
|
||||
if (ioctl(fd, TUNSETIFF, &ifr) < 0) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue