if (value[strlen(value) - 1] == '+' && netdev->type == LXC_NET_PHYS)
ret = create_matched_ifnames(value, lxc_conf, netdev);
else
- ret = network_ifname(netdev->link, value);
+ ret = network_ifname(netdev->link, value, sizeof(netdev->link));
return ret;
}
if (!netdev)
return -1;
- return network_ifname(netdev->name, value);
+ return network_ifname(netdev->name, value, sizeof(netdev->name));
}
static int set_config_net_veth_pair(const char *key, const char *value,
if (!netdev)
return -1;
- return network_ifname(netdev->priv.veth_attr.pair, value);
+ return network_ifname(netdev->priv.veth_attr.pair, value, sizeof(netdev->priv.veth_attr.pair));
}
static int set_config_net_macvlan_mode(const char *key, const char *value,
#include "parse.h"
#include "utils.h"
+#ifndef HAVE_STRLCPY
+#include "include/strlcpy.h"
+#endif
+
lxc_log_define(lxc_confile_utils, lxc);
int parse_idmaps(const char *idmap, char *type, unsigned long *nsid,
return 0;
}
-int network_ifname(char *valuep, const char *value)
+int network_ifname(char *valuep, const char *value, size_t size)
{
- if (strlen(value) >= IFNAMSIZ) {
+ size_t retlen;
+
+ if (!valuep || !value)
+ return -1;
+
+ retlen = strlcpy(valuep, value, size);
+ if (retlen >= size) {
ERROR("Network devie name \"%s\" is too long (>= %zu)", value,
- (size_t)IFNAMSIZ);
+ size);
}
- strcpy(valuep, value);
return 0;
}
size_t max);
extern int set_config_path_item(char **conf_item, const char *value);
extern int config_ip_prefix(struct in_addr *addr);
-extern int network_ifname(char *valuep, const char *value);
+extern int network_ifname(char *valuep, const char *value, size_t size);
extern int rand_complete_hwaddr(char *hwaddr);
extern bool lxc_config_net_hwaddr(const char *line);
extern void update_hwaddr(const char *line);
#include <lxc/lxccontainer.h>
+#ifndef HAVE_STRLCPY
+#include "include/strlcpy.h"
+#endif
+
#define TSTNAME "lxc-attach-test"
#define TSTOUT(fmt, ...) do { \
fprintf(stdout, fmt, ##__VA_ARGS__); fflush(NULL); \
char template[sizeof(P_tmpdir"/attach_XXXXXX")];
int fret = EXIT_FAILURE;
- strcpy(template, P_tmpdir"/attach_XXXXXX");
+ (void)strlcpy(template, P_tmpdir"/attach_XXXXXX", sizeof(template));
+
i = lxc_make_tmpfile(template, false);
if (i < 0) {
lxc_error("Failed to create temporary log file for container %s\n", TSTNAME);
#include "lxc.h"
#include "commands.h"
+#ifndef HAVE_STRLCPY
+#include "include/strlcpy.h"
+#endif
+
#define MYNAME "lxctest1"
#define TSTERR(fmt, ...) do { \
TSTERR("cgroup_get failed");
goto err3;
}
- strcpy(value_save, value);
+ (void)strlcpy(value_save, value, NAME_MAX);
ret = cgroup_ops->set(cgroup_ops, "memory.soft_limit_in_bytes", "512M",
c->name, c->config_path);
#include "lxctest.h"
#include "utils.h"
+#ifndef HAVE_STRLCPY
+#include "include/strlcpy.h"
+#endif
+
#define MYNAME "shortlived"
static int destroy_container(void)
char template[sizeof(P_tmpdir"/shortlived_XXXXXX")];
int ret = EXIT_FAILURE;
- strcpy(template, P_tmpdir"/shortlived_XXXXXX");
+ (void)strlcpy(template, P_tmpdir"/shortlived_XXXXXX", sizeof(template));
+
i = lxc_make_tmpfile(template, false);
if (i < 0) {
lxc_error("Failed to create temporary log file for container %s\n", MYNAME);