Commit 369f366a authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

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: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent bc002e85
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "crtools.h" #include "crtools.h"
#include "protobuf.h" #include "protobuf.h"
#include "cr-show.h" #include "cr-show.h"
#include "string.h"
#include "files.h" #include "files.h"
#include "files-reg.h" #include "files-reg.h"
#include "tun.h" #include "tun.h"
...@@ -92,7 +93,7 @@ static int list_tun_link(NetDeviceEntry *nde) ...@@ -92,7 +93,7 @@ static int list_tun_link(NetDeviceEntry *nde)
if (!tl) if (!tl)
return -1; return -1;
strcpy(tl->name, nde->name); strlcpy(tl->name, nde->name, sizeof(tl->name));
/* /*
* Keep tun-flags not only for persistency fixup (see * Keep tun-flags not only for persistency fixup (see
* commend below), but also for TUNSETIFF -- we must * 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) ...@@ -123,7 +124,7 @@ static struct tun_link *__dump_tun_link_fd(int fd, char *name, unsigned flags)
tl = xmalloc(sizeof(*tl)); tl = xmalloc(sizeof(*tl));
if (!tl) if (!tl)
goto err; goto err;
strcpy(tl->name, name); strlcpy(tl->name, name, sizeof(tl->name));
if (ioctl(fd, TUNGETVNETHDRSZ, &tl->dmp.vnethdr) < 0) { if (ioctl(fd, TUNGETVNETHDRSZ, &tl->dmp.vnethdr) < 0) {
pr_perror("Can't dump vnethdr size for %s", name); 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) ...@@ -209,7 +210,7 @@ static int open_tun_dev(char *name, unsigned int idx, unsigned flags)
} }
memset(&ifr, 0, sizeof(ifr)); memset(&ifr, 0, sizeof(ifr));
strcpy(ifr.ifr_name, name); strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
ifr.ifr_flags = flags; ifr.ifr_flags = flags;
if (ioctl(fd, TUNSETIFF, &ifr)) { if (ioctl(fd, TUNSETIFF, &ifr)) {
...@@ -333,7 +334,7 @@ static int tunfile_open(struct file_desc *d) ...@@ -333,7 +334,7 @@ static int tunfile_open(struct file_desc *d)
} }
memset(&ifr, 0, sizeof(ifr)); 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; ifr.ifr_flags = tl->rst.flags;
if (ioctl(fd, TUNSETIFF, &ifr) < 0) { if (ioctl(fd, TUNSETIFF, &ifr) < 0) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment