Unverified Commit cc98c470 by Stéphane Graber Committed by GitHub

Merge pull request #3739 from brauner/2021-03-27/fixes

oss-fuzz: fixes
parents 6a374b65 b2606302
...@@ -29,7 +29,7 @@ jobs: ...@@ -29,7 +29,7 @@ jobs:
with: with:
oss-fuzz-project-name: 'lxc' oss-fuzz-project-name: 'lxc'
fuzz-seconds: 180 fuzz-seconds: 180
dry-run: true dry-run: ${{ matrix.sanitizer != 'address' }}
sanitizer: ${{ matrix.sanitizer }} sanitizer: ${{ matrix.sanitizer }}
- name: Upload Crash - name: Upload Crash
uses: actions/upload-artifact@v1 uses: actions/upload-artifact@v1
......
...@@ -3627,6 +3627,7 @@ int lxc_clear_config_caps(struct lxc_conf *c) ...@@ -3627,6 +3627,7 @@ int lxc_clear_config_caps(struct lxc_conf *c)
free(it); free(it);
} }
lxc_list_init(&c->caps);
return 0; return 0;
} }
...@@ -3640,6 +3641,7 @@ static int lxc_free_idmap(struct lxc_list *id_map) ...@@ -3640,6 +3641,7 @@ static int lxc_free_idmap(struct lxc_list *id_map)
free(it); free(it);
} }
lxc_list_init(id_map);
return 0; return 0;
} }
...@@ -3666,16 +3668,15 @@ int lxc_clear_config_keepcaps(struct lxc_conf *c) ...@@ -3666,16 +3668,15 @@ int lxc_clear_config_keepcaps(struct lxc_conf *c)
free(it); free(it);
} }
lxc_list_init(&c->keepcaps);
return 0; return 0;
} }
int lxc_clear_namespace(struct lxc_conf *c) int lxc_clear_namespace(struct lxc_conf *c)
{ {
int i; for (int i = 0; i < LXC_NS_MAX; i++)
for (i = 0; i < LXC_NS_MAX; i++) { free_disarm(c->ns_share[i]);
free(c->ns_share[i]);
c->ns_share[i] = NULL;
}
return 0; return 0;
} }
...@@ -3708,7 +3709,7 @@ int lxc_clear_cgroups(struct lxc_conf *c, const char *key, int version) ...@@ -3708,7 +3709,7 @@ int lxc_clear_cgroups(struct lxc_conf *c, const char *key, int version)
else else
return ret_errno(EINVAL); return ret_errno(EINVAL);
lxc_list_for_each_safe (it, list, next) { lxc_list_for_each_safe(it, list, next) {
struct lxc_cgroup *cg = it->elem; struct lxc_cgroup *cg = it->elem;
if (!all && !strequal(cg->subsystem, k)) if (!all && !strequal(cg->subsystem, k))
...@@ -3721,6 +3722,9 @@ int lxc_clear_cgroups(struct lxc_conf *c, const char *key, int version) ...@@ -3721,6 +3722,9 @@ int lxc_clear_cgroups(struct lxc_conf *c, const char *key, int version)
free(it); free(it);
} }
if (all)
lxc_list_init(list);
return 0; return 0;
} }
...@@ -3808,7 +3812,7 @@ int lxc_clear_procs(struct lxc_conf *c, const char *key) ...@@ -3808,7 +3812,7 @@ int lxc_clear_procs(struct lxc_conf *c, const char *key)
else else
return -1; return -1;
lxc_list_for_each_safe (it, &c->procs, next) { lxc_list_for_each_safe(it, &c->procs, next) {
struct lxc_proc *proc = it->elem; struct lxc_proc *proc = it->elem;
if (!all && !strequal(proc->filename, k)) if (!all && !strequal(proc->filename, k))
...@@ -3821,6 +3825,9 @@ int lxc_clear_procs(struct lxc_conf *c, const char *key) ...@@ -3821,6 +3825,9 @@ int lxc_clear_procs(struct lxc_conf *c, const char *key)
free(it); free(it);
} }
if (all)
lxc_list_init(&c->procs);
return 0; return 0;
} }
...@@ -3834,6 +3841,7 @@ int lxc_clear_groups(struct lxc_conf *c) ...@@ -3834,6 +3841,7 @@ int lxc_clear_groups(struct lxc_conf *c)
free(it); free(it);
} }
lxc_list_init(&c->groups);
return 0; return 0;
} }
...@@ -3847,6 +3855,7 @@ int lxc_clear_environment(struct lxc_conf *c) ...@@ -3847,6 +3855,7 @@ int lxc_clear_environment(struct lxc_conf *c)
free(it); free(it);
} }
lxc_list_init(&c->environment);
return 0; return 0;
} }
...@@ -3860,6 +3869,7 @@ int lxc_clear_mount_entries(struct lxc_conf *c) ...@@ -3860,6 +3869,7 @@ int lxc_clear_mount_entries(struct lxc_conf *c)
free(it); free(it);
} }
lxc_list_init(&c->mount_list);
return 0; return 0;
} }
...@@ -3871,7 +3881,6 @@ int lxc_clear_automounts(struct lxc_conf *c) ...@@ -3871,7 +3881,6 @@ int lxc_clear_automounts(struct lxc_conf *c)
int lxc_clear_hooks(struct lxc_conf *c, const char *key) int lxc_clear_hooks(struct lxc_conf *c, const char *key)
{ {
int i;
struct lxc_list *it, *next; struct lxc_list *it, *next;
const char *k = NULL; const char *k = NULL;
bool all = false, done = false; bool all = false, done = false;
...@@ -3883,13 +3892,14 @@ int lxc_clear_hooks(struct lxc_conf *c, const char *key) ...@@ -3883,13 +3892,14 @@ int lxc_clear_hooks(struct lxc_conf *c, const char *key)
else else
return -1; return -1;
for (i = 0; i < NUM_LXC_HOOKS; i++) { for (int i = 0; i < NUM_LXC_HOOKS; i++) {
if (all || strequal(k, lxchook_names[i])) { if (all || strequal(k, lxchook_names[i])) {
lxc_list_for_each_safe (it, &c->hooks[i], next) { lxc_list_for_each_safe (it, &c->hooks[i], next) {
lxc_list_del(it); lxc_list_del(it);
free(it->elem); free(it->elem);
free(it); free(it);
} }
lxc_list_init(&c->hooks[i]);
done = true; done = true;
} }
...@@ -3910,17 +3920,21 @@ static inline void lxc_clear_aliens(struct lxc_conf *conf) ...@@ -3910,17 +3920,21 @@ static inline void lxc_clear_aliens(struct lxc_conf *conf)
free(it->elem); free(it->elem);
free(it); free(it);
} }
lxc_list_init(&conf->aliens);
} }
void lxc_clear_includes(struct lxc_conf *conf) void lxc_clear_includes(struct lxc_conf *conf)
{ {
struct lxc_list *it, *next; struct lxc_list *it, *next;
lxc_list_for_each_safe (it, &conf->includes, next) { lxc_list_for_each_safe(it, &conf->includes, next) {
lxc_list_del(it); lxc_list_del(it);
free(it->elem); free(it->elem);
free(it); free(it);
} }
lxc_list_init(&conf->includes);
} }
int lxc_clear_apparmor_raw(struct lxc_conf *c) int lxc_clear_apparmor_raw(struct lxc_conf *c)
...@@ -3933,6 +3947,7 @@ int lxc_clear_apparmor_raw(struct lxc_conf *c) ...@@ -3933,6 +3947,7 @@ int lxc_clear_apparmor_raw(struct lxc_conf *c)
free(it); free(it);
} }
lxc_list_init(&c->lsm_aa_raw);
return 0; return 0;
} }
......
...@@ -321,12 +321,12 @@ static int set_config_net_type(const char *key, const char *value, ...@@ -321,12 +321,12 @@ static int set_config_net_type(const char *key, const char *value,
{ {
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_type(key, lxc_conf, data);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (lxc_config_value_empty(value))
return clr_config_net_type(key, lxc_conf, data);
if (strequal(value, "veth")) { if (strequal(value, "veth")) {
netdev->type = LXC_NET_VETH; netdev->type = LXC_NET_VETH;
lxc_list_init(&netdev->priv.veth_attr.ipv4_routes); lxc_list_init(&netdev->priv.veth_attr.ipv4_routes);
...@@ -364,12 +364,12 @@ static int set_config_net_flags(const char *key, const char *value, ...@@ -364,12 +364,12 @@ static int set_config_net_flags(const char *key, const char *value,
{ {
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_flags(key, lxc_conf, data);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (lxc_config_value_empty(value))
return clr_config_net_flags(key, lxc_conf, data);
netdev->flags |= IFF_UP; netdev->flags |= IFF_UP;
return 0; return 0;
...@@ -422,12 +422,12 @@ static int set_config_net_link(const char *key, const char *value, ...@@ -422,12 +422,12 @@ static int set_config_net_link(const char *key, const char *value,
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
int ret = 0; int ret = 0;
if (lxc_config_value_empty(value))
return clr_config_net_link(key, lxc_conf, data);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (lxc_config_value_empty(value))
return clr_config_net_link(key, lxc_conf, data);
if (value[strlen(value) - 1] == '+' && netdev->type == LXC_NET_PHYS) if (value[strlen(value) - 1] == '+' && netdev->type == LXC_NET_PHYS)
ret = create_matched_ifnames(value, lxc_conf, netdev); ret = create_matched_ifnames(value, lxc_conf, netdev);
else else
...@@ -443,12 +443,12 @@ static int set_config_net_l2proxy(const char *key, const char *value, ...@@ -443,12 +443,12 @@ static int set_config_net_l2proxy(const char *key, const char *value,
unsigned int val = 0; unsigned int val = 0;
int ret; int ret;
if (lxc_config_value_empty(value))
return clr_config_net_l2proxy(key, lxc_conf, data);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (lxc_config_value_empty(value))
return clr_config_net_l2proxy(key, lxc_conf, data);
ret = lxc_safe_uint(value, &val); ret = lxc_safe_uint(value, &val);
if (ret < 0) if (ret < 0)
return ret_errno(ret); return ret_errno(ret);
...@@ -470,12 +470,12 @@ static int set_config_net_name(const char *key, const char *value, ...@@ -470,12 +470,12 @@ static int set_config_net_name(const char *key, const char *value,
{ {
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_name(key, lxc_conf, data);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (lxc_config_value_empty(value))
return clr_config_net_name(key, lxc_conf, data);
return network_ifname(netdev->name, value, sizeof(netdev->name)); return network_ifname(netdev->name, value, sizeof(netdev->name));
} }
...@@ -485,6 +485,12 @@ static int set_config_net_veth_mode(const char *key, const char *value, ...@@ -485,6 +485,12 @@ static int set_config_net_veth_mode(const char *key, const char *value,
{ {
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VETH)
return ret_errno(EINVAL);
if (lxc_config_value_empty(value)) if (lxc_config_value_empty(value))
return clr_config_net_veth_mode(key, lxc_conf, data); return clr_config_net_veth_mode(key, lxc_conf, data);
...@@ -499,12 +505,15 @@ static int set_config_net_veth_pair(const char *key, const char *value, ...@@ -499,12 +505,15 @@ static int set_config_net_veth_pair(const char *key, const char *value,
{ {
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_veth_pair(key, lxc_conf, data);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VETH)
return ret_errno(EINVAL);
if (lxc_config_value_empty(value))
return clr_config_net_veth_pair(key, lxc_conf, data);
return network_ifname(netdev->priv.veth_attr.pair, value, return network_ifname(netdev->priv.veth_attr.pair, value,
sizeof(netdev->priv.veth_attr.pair)); sizeof(netdev->priv.veth_attr.pair));
} }
...@@ -518,6 +527,9 @@ static int set_config_net_veth_vlan_id(const char *key, const char *value, ...@@ -518,6 +527,9 @@ static int set_config_net_veth_vlan_id(const char *key, const char *value,
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VETH)
return ret_errno(EINVAL);
if (lxc_config_value_empty(value)) if (lxc_config_value_empty(value))
return clr_config_net_veth_vlan_id(key, lxc_conf, data); return clr_config_net_veth_vlan_id(key, lxc_conf, data);
...@@ -541,7 +553,8 @@ static int set_config_net_veth_vlan_id(const char *key, const char *value, ...@@ -541,7 +553,8 @@ static int set_config_net_veth_vlan_id(const char *key, const char *value,
} }
static int set_config_net_veth_vlan_tagged_id(const char *key, const char *value, static int set_config_net_veth_vlan_tagged_id(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data) struct lxc_conf *lxc_conf,
void *data)
{ {
__do_free struct lxc_list *list = NULL; __do_free struct lxc_list *list = NULL;
int ret; int ret;
...@@ -551,6 +564,9 @@ static int set_config_net_veth_vlan_tagged_id(const char *key, const char *value ...@@ -551,6 +564,9 @@ static int set_config_net_veth_vlan_tagged_id(const char *key, const char *value
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VETH)
return ret_errno(EINVAL);
if (lxc_config_value_empty(value)) if (lxc_config_value_empty(value))
return clr_config_net_veth_vlan_tagged_id(key, lxc_conf, data); return clr_config_net_veth_vlan_tagged_id(key, lxc_conf, data);
...@@ -577,12 +593,15 @@ static int set_config_net_macvlan_mode(const char *key, const char *value, ...@@ -577,12 +593,15 @@ static int set_config_net_macvlan_mode(const char *key, const char *value,
{ {
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_macvlan_mode(key, lxc_conf, data);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_MACVLAN)
return ret_errno(EINVAL);
if (lxc_config_value_empty(value))
return clr_config_net_macvlan_mode(key, lxc_conf, data);
return lxc_macvlan_mode_to_flag(&netdev->priv.macvlan_attr.mode, value); return lxc_macvlan_mode_to_flag(&netdev->priv.macvlan_attr.mode, value);
} }
...@@ -591,16 +610,14 @@ static int set_config_net_ipvlan_mode(const char *key, const char *value, ...@@ -591,16 +610,14 @@ static int set_config_net_ipvlan_mode(const char *key, const char *value,
{ {
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_ipvlan_mode(key, lxc_conf, data);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_IPVLAN) if (netdev->type != LXC_NET_IPVLAN)
return log_error_errno(-EINVAL, return syserror_set(-EINVAL, "Invalid ipvlan mode \"%s\", can only be used with ipvlan network", value);
EINVAL, "Invalid ipvlan mode \"%s\", can only be used with ipvlan network",
value); if (lxc_config_value_empty(value))
return clr_config_net_ipvlan_mode(key, lxc_conf, data);
return lxc_ipvlan_mode_to_flag(&netdev->priv.ipvlan_attr.mode, value); return lxc_ipvlan_mode_to_flag(&netdev->priv.ipvlan_attr.mode, value);
} }
...@@ -610,16 +627,14 @@ static int set_config_net_ipvlan_isolation(const char *key, const char *value, ...@@ -610,16 +627,14 @@ static int set_config_net_ipvlan_isolation(const char *key, const char *value,
{ {
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_ipvlan_isolation(key, lxc_conf, data);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_IPVLAN) if (netdev->type != LXC_NET_IPVLAN)
return log_error_errno(-EINVAL, return syserror_set(-EINVAL, "Invalid ipvlan isolation \"%s\", can only be used with ipvlan network", value);
EINVAL, "Invalid ipvlan isolation \"%s\", can only be used with ipvlan network",
value); if (lxc_config_value_empty(value))
return clr_config_net_ipvlan_isolation(key, lxc_conf, data);
return lxc_ipvlan_isolation_to_flag(&netdev->priv.ipvlan_attr.isolation, value); return lxc_ipvlan_isolation_to_flag(&netdev->priv.ipvlan_attr.isolation, value);
} }
...@@ -630,21 +645,20 @@ static int set_config_net_hwaddr(const char *key, const char *value, ...@@ -630,21 +645,20 @@ static int set_config_net_hwaddr(const char *key, const char *value,
__do_free char *new_value = NULL; __do_free char *new_value = NULL;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_hwaddr(key, lxc_conf, data);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (lxc_config_value_empty(value))
return clr_config_net_hwaddr(key, lxc_conf, data);
new_value = strdup(value); new_value = strdup(value);
if (!new_value) if (!new_value)
return ret_errno(ENOMEM); return ret_errno(ENOMEM);
rand_complete_hwaddr(new_value); rand_complete_hwaddr(new_value);
if (lxc_config_value_empty(new_value))
free_disarm(netdev->hwaddr); free_disarm(netdev->hwaddr);
else if (!lxc_config_value_empty(new_value))
netdev->hwaddr = move_ptr(new_value); netdev->hwaddr = move_ptr(new_value);
return 0; return 0;
...@@ -656,12 +670,15 @@ static int set_config_net_vlan_id(const char *key, const char *value, ...@@ -656,12 +670,15 @@ static int set_config_net_vlan_id(const char *key, const char *value,
int ret; int ret;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_vlan_id(key, lxc_conf, data);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VLAN)
return ret_errno(EINVAL);
if (lxc_config_value_empty(value))
return clr_config_net_vlan_id(key, lxc_conf, data);
ret = get_u16(&netdev->priv.vlan_attr.vid, value, 0); ret = get_u16(&netdev->priv.vlan_attr.vid, value, 0);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -674,12 +691,12 @@ static int set_config_net_mtu(const char *key, const char *value, ...@@ -674,12 +691,12 @@ static int set_config_net_mtu(const char *key, const char *value,
{ {
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_mtu(key, lxc_conf, data);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (lxc_config_value_empty(value))
return clr_config_net_mtu(key, lxc_conf, data);
return set_config_string_item(&netdev->mtu, value); return set_config_string_item(&netdev->mtu, value);
} }
...@@ -694,12 +711,12 @@ static int set_config_net_ipv4_address(const char *key, const char *value, ...@@ -694,12 +711,12 @@ static int set_config_net_ipv4_address(const char *key, const char *value,
char *cursor, *slash; char *cursor, *slash;
char *bcast = NULL, *prefix = NULL; char *bcast = NULL, *prefix = NULL;
if (lxc_config_value_empty(value))
return clr_config_net_ipv4_address(key, lxc_conf, data);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (lxc_config_value_empty(value))
return clr_config_net_ipv4_address(key, lxc_conf, data);
inetdev = zalloc(sizeof(*inetdev)); inetdev = zalloc(sizeof(*inetdev));
if (!inetdev) if (!inetdev)
return ret_errno(ENOMEM); return ret_errno(ENOMEM);
...@@ -765,12 +782,12 @@ static int set_config_net_ipv4_gateway(const char *key, const char *value, ...@@ -765,12 +782,12 @@ static int set_config_net_ipv4_gateway(const char *key, const char *value,
{ {
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
if (lxc_config_value_empty(value)) if (lxc_config_value_empty(value))
return clr_config_net_ipv4_gateway(key, lxc_conf, data); return clr_config_net_ipv4_gateway(key, lxc_conf, data);
if (!netdev)
return -1;
free(netdev->ipv4_gateway); free(netdev->ipv4_gateway);
if (strequal(value, "auto")) { if (strequal(value, "auto")) {
...@@ -809,16 +826,14 @@ static int set_config_net_veth_ipv4_route(const char *key, const char *value, ...@@ -809,16 +826,14 @@ static int set_config_net_veth_ipv4_route(const char *key, const char *value,
char *netmask, *slash; char *netmask, *slash;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_veth_ipv4_route(key, lxc_conf, data);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VETH) if (netdev->type != LXC_NET_VETH)
return log_error_errno(-EINVAL, return syserror_set(-EINVAL, "Invalid ipv4 route \"%s\", can only be used with veth network", value);
EINVAL, "Invalid ipv4 route \"%s\", can only be used with veth network",
value); if (lxc_config_value_empty(value))
return clr_config_net_veth_ipv4_route(key, lxc_conf, data);
inetdev = zalloc(sizeof(*inetdev)); inetdev = zalloc(sizeof(*inetdev));
if (!inetdev) if (!inetdev)
...@@ -870,12 +885,12 @@ static int set_config_net_ipv6_address(const char *key, const char *value, ...@@ -870,12 +885,12 @@ static int set_config_net_ipv6_address(const char *key, const char *value,
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
char *slash, *netmask; char *slash, *netmask;
if (lxc_config_value_empty(value))
return clr_config_net_ipv6_address(key, lxc_conf, data);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (lxc_config_value_empty(value))
return clr_config_net_ipv6_address(key, lxc_conf, data);
inet6dev = zalloc(sizeof(*inet6dev)); inet6dev = zalloc(sizeof(*inet6dev));
if (!inet6dev) if (!inet6dev)
return ret_errno(ENOMEM); return ret_errno(ENOMEM);
...@@ -916,12 +931,12 @@ static int set_config_net_ipv6_gateway(const char *key, const char *value, ...@@ -916,12 +931,12 @@ static int set_config_net_ipv6_gateway(const char *key, const char *value,
{ {
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_ipv6_gateway(key, lxc_conf, data);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (lxc_config_value_empty(value))
return clr_config_net_ipv6_gateway(key, lxc_conf, data);
free(netdev->ipv6_gateway); free(netdev->ipv6_gateway);
if (strequal(value, "auto")) { if (strequal(value, "auto")) {
...@@ -961,16 +976,14 @@ static int set_config_net_veth_ipv6_route(const char *key, const char *value, ...@@ -961,16 +976,14 @@ static int set_config_net_veth_ipv6_route(const char *key, const char *value,
char *netmask, *slash; char *netmask, *slash;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_veth_ipv6_route(key, lxc_conf, data);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VETH) if (netdev->type != LXC_NET_VETH)
return log_error_errno(-EINVAL, return syserror_set(-EINVAL, "Invalid ipv6 route \"%s\", can only be used with veth network", value);
EINVAL, "Invalid ipv6 route \"%s\", can only be used with veth network",
value); if (lxc_config_value_empty(value))
return clr_config_net_veth_ipv6_route(key, lxc_conf, data);
inet6dev = zalloc(sizeof(*inet6dev)); inet6dev = zalloc(sizeof(*inet6dev));
if (!inet6dev) if (!inet6dev)
...@@ -1016,12 +1029,12 @@ static int set_config_net_script_up(const char *key, const char *value, ...@@ -1016,12 +1029,12 @@ static int set_config_net_script_up(const char *key, const char *value,
{ {
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_script_up(key, lxc_conf, data);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (lxc_config_value_empty(value))
return clr_config_net_script_up(key, lxc_conf, data);
return set_config_string_item(&netdev->upscript, value); return set_config_string_item(&netdev->upscript, value);
} }
...@@ -1030,12 +1043,12 @@ static int set_config_net_script_down(const char *key, const char *value, ...@@ -1030,12 +1043,12 @@ static int set_config_net_script_down(const char *key, const char *value,
{ {
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (lxc_config_value_empty(value))
return clr_config_net_script_down(key, lxc_conf, data);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (lxc_config_value_empty(value))
return clr_config_net_script_down(key, lxc_conf, data);
return set_config_string_item(&netdev->downscript, value); return set_config_string_item(&netdev->downscript, value);
} }
...@@ -5171,7 +5184,7 @@ static struct lxc_config_t *get_network_config_ops(const char *key, ...@@ -5171,7 +5184,7 @@ static struct lxc_config_t *get_network_config_ops(const char *key,
char *idx_start, *idx_end; char *idx_start, *idx_end;
/* check that this is a sensible network key */ /* check that this is a sensible network key */
if (!strnequal("lxc.net.", key, 8)) if (!strnequal("lxc.net.", key, STRLITERALLEN("lxc.net.")))
return log_error_errno(NULL, EINVAL, "Invalid network configuration key \"%s\"", key); return log_error_errno(NULL, EINVAL, "Invalid network configuration key \"%s\"", key);
copy = strdup(key); copy = strdup(key);
...@@ -5179,15 +5192,15 @@ static struct lxc_config_t *get_network_config_ops(const char *key, ...@@ -5179,15 +5192,15 @@ static struct lxc_config_t *get_network_config_ops(const char *key,
return log_error_errno(NULL, ENOMEM, "Failed to duplicate string \"%s\"", key); return log_error_errno(NULL, ENOMEM, "Failed to duplicate string \"%s\"", key);
/* lxc.net.<n> */ /* lxc.net.<n> */
if (!isdigit(*(key + 8))) if (!isdigit(*(key + STRLITERALLEN("lxc.net."))))
return log_error_errno(NULL, EINVAL, "Failed to detect digit in string \"%s\"", key + 8); return log_error_errno(NULL, EINVAL, "Failed to detect digit in string \"%s\"", key + 8);
/* beginning of index string */ /* beginning of index string */
idx_start = (copy + 7); idx_start = copy + (STRLITERALLEN("lxc.net.") - 1);
*idx_start = '\0'; *idx_start = '\0';
/* end of index string */ /* end of index string */
idx_end = strchr((copy + 8), '.'); idx_end = strchr((copy + STRLITERALLEN("lxc.net.")), '.');
if (idx_end) if (idx_end)
*idx_end = '\0'; *idx_end = '\0';
...@@ -5202,7 +5215,7 @@ static struct lxc_config_t *get_network_config_ops(const char *key, ...@@ -5202,7 +5215,7 @@ static struct lxc_config_t *get_network_config_ops(const char *key,
* better safe than sorry. * better safe than sorry.
* (Checking for INT_MAX here is intentional.) * (Checking for INT_MAX here is intentional.)
*/ */
if (tmpidx == INT_MAX) if (tmpidx >= INT_MAX)
return log_error_errno(NULL, ERANGE, "Number of configured networks would overflow the counter"); return log_error_errno(NULL, ERANGE, "Number of configured networks would overflow the counter");
*idx = tmpidx; *idx = tmpidx;
...@@ -5216,8 +5229,10 @@ static struct lxc_config_t *get_network_config_ops(const char *key, ...@@ -5216,8 +5229,10 @@ static struct lxc_config_t *get_network_config_ops(const char *key,
*idx_end = '.'; *idx_end = '.';
if (strlen(idx_end + 1) == 0) if (strlen(idx_end + 1) == 0)
return log_error_errno(NULL, EINVAL, "No subkey in network configuration key \"%s\"", key); return log_error_errno(NULL, EINVAL, "No subkey in network configuration key \"%s\"", key);
if (isdigit(*(idx_end + 1)))
return log_error_errno(NULL, EINVAL, "Key can't contain more than one index");
memmove(copy + 8, idx_end + 1, strlen(idx_end + 1)); memmove(copy + STRLITERALLEN("lxc.net."), idx_end + 1, strlen(idx_end + 1));
copy[strlen(key) - (numstrlen + 1)] = '\0'; copy[strlen(key) - (numstrlen + 1)] = '\0';
config = lxc_get_config(copy); config = lxc_get_config(copy);
...@@ -5441,6 +5456,9 @@ static int clr_config_net_veth_pair(const char *key, struct lxc_conf *lxc_conf, ...@@ -5441,6 +5456,9 @@ static int clr_config_net_veth_pair(const char *key, struct lxc_conf *lxc_conf,
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VETH)
return 0;
netdev->priv.veth_attr.pair[0] = '\0'; netdev->priv.veth_attr.pair[0] = '\0';
return 0; return 0;
...@@ -5454,6 +5472,9 @@ static int clr_config_net_veth_vlan_id(const char *key, struct lxc_conf *lxc_con ...@@ -5454,6 +5472,9 @@ static int clr_config_net_veth_vlan_id(const char *key, struct lxc_conf *lxc_con
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VETH)
return 0;
netdev->priv.veth_attr.vlan_id = 0; netdev->priv.veth_attr.vlan_id = 0;
netdev->priv.veth_attr.vlan_id_set = false; netdev->priv.veth_attr.vlan_id_set = false;
...@@ -5469,6 +5490,9 @@ static int clr_config_net_veth_vlan_tagged_id(const char *key, ...@@ -5469,6 +5490,9 @@ static int clr_config_net_veth_vlan_tagged_id(const char *key,
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VETH)
return 0;
lxc_list_for_each_safe(cur, &netdev->priv.veth_attr.vlan_tagged_ids, next) { lxc_list_for_each_safe(cur, &netdev->priv.veth_attr.vlan_tagged_ids, next) {
lxc_list_del(cur); lxc_list_del(cur);
free(cur); free(cur);
...@@ -5538,6 +5562,9 @@ static int clr_config_net_vlan_id(const char *key, struct lxc_conf *lxc_conf, ...@@ -5538,6 +5562,9 @@ static int clr_config_net_vlan_id(const char *key, struct lxc_conf *lxc_conf,
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VLAN)
return 0;
netdev->priv.vlan_attr.vid = 0; netdev->priv.vlan_attr.vid = 0;
return 0; return 0;
...@@ -5583,6 +5610,9 @@ static int clr_config_net_veth_ipv4_route(const char *key, ...@@ -5583,6 +5610,9 @@ static int clr_config_net_veth_ipv4_route(const char *key,
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VETH)
return 0;
lxc_list_for_each_safe(cur, &netdev->priv.veth_attr.ipv4_routes, next) { lxc_list_for_each_safe(cur, &netdev->priv.veth_attr.ipv4_routes, next) {
lxc_list_del(cur); lxc_list_del(cur);
free(cur->elem); free(cur->elem);
...@@ -5632,6 +5662,9 @@ static int clr_config_net_veth_ipv6_route(const char *key, ...@@ -5632,6 +5662,9 @@ static int clr_config_net_veth_ipv6_route(const char *key,
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VETH)
return 0;
lxc_list_for_each_safe(cur, &netdev->priv.veth_attr.ipv6_routes, next) { lxc_list_for_each_safe(cur, &netdev->priv.veth_attr.ipv6_routes, next) {
lxc_list_del(cur); lxc_list_del(cur);
free(cur->elem); free(cur->elem);
...@@ -5672,14 +5705,14 @@ static int get_config_net_type(const char *key, char *retv, int inlen, ...@@ -5672,14 +5705,14 @@ static int get_config_net_type(const char *key, char *retv, int inlen,
int fulllen = 0; int fulllen = 0;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
if (!retv) if (!retv)
inlen = 0; inlen = 0;
else else
memset(retv, 0, inlen); memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
strprint(retv, inlen, "%s", lxc_net_type_to_str(netdev->type)); strprint(retv, inlen, "%s", lxc_net_type_to_str(netdev->type));
return fulllen; return fulllen;
...@@ -5692,14 +5725,14 @@ static int get_config_net_flags(const char *key, char *retv, int inlen, ...@@ -5692,14 +5725,14 @@ static int get_config_net_flags(const char *key, char *retv, int inlen,
int fulllen = 0; int fulllen = 0;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
if (!retv) if (!retv)
inlen = 0; inlen = 0;
else else
memset(retv, 0, inlen); memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
if (netdev->flags & IFF_UP) if (netdev->flags & IFF_UP)
strprint(retv, inlen, "up"); strprint(retv, inlen, "up");
...@@ -5713,14 +5746,14 @@ static int get_config_net_link(const char *key, char *retv, int inlen, ...@@ -5713,14 +5746,14 @@ static int get_config_net_link(const char *key, char *retv, int inlen,
int fulllen = 0; int fulllen = 0;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
if (!retv) if (!retv)
inlen = 0; inlen = 0;
else else
memset(retv, 0, inlen); memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
if (netdev->link[0] != '\0') if (netdev->link[0] != '\0')
strprint(retv, inlen, "%s", netdev->link); strprint(retv, inlen, "%s", netdev->link);
...@@ -5731,6 +5764,10 @@ static int get_config_net_l2proxy(const char *key, char *retv, int inlen, ...@@ -5731,6 +5764,10 @@ static int get_config_net_l2proxy(const char *key, char *retv, int inlen,
struct lxc_conf *c, void *data) struct lxc_conf *c, void *data)
{ {
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
return lxc_get_conf_bool(c, retv, inlen, netdev->l2proxy); return lxc_get_conf_bool(c, retv, inlen, netdev->l2proxy);
} }
...@@ -5741,14 +5778,14 @@ static int get_config_net_name(const char *key, char *retv, int inlen, ...@@ -5741,14 +5778,14 @@ static int get_config_net_name(const char *key, char *retv, int inlen,
int fulllen = 0; int fulllen = 0;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
if (!retv) if (!retv)
inlen = 0; inlen = 0;
else else
memset(retv, 0, inlen); memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
if (netdev->name[0] != '\0') if (netdev->name[0] != '\0')
strprint(retv, inlen, "%s", netdev->name); strprint(retv, inlen, "%s", netdev->name);
...@@ -5763,16 +5800,16 @@ static int get_config_net_macvlan_mode(const char *key, char *retv, int inlen, ...@@ -5763,16 +5800,16 @@ static int get_config_net_macvlan_mode(const char *key, char *retv, int inlen,
const char *mode; const char *mode;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_MACVLAN) if (netdev->type != LXC_NET_MACVLAN)
return 0; return ret_errno(EINVAL);
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
switch (netdev->priv.macvlan_attr.mode) { switch (netdev->priv.macvlan_attr.mode) {
case MACVLAN_MODE_PRIVATE: case MACVLAN_MODE_PRIVATE:
...@@ -5805,16 +5842,16 @@ static int get_config_net_ipvlan_mode(const char *key, char *retv, int inlen, ...@@ -5805,16 +5842,16 @@ static int get_config_net_ipvlan_mode(const char *key, char *retv, int inlen,
int len; int len;
const char *mode; const char *mode;
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_IPVLAN) if (netdev->type != LXC_NET_IPVLAN)
return 0; return ret_errno(EINVAL);
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
switch (netdev->priv.ipvlan_attr.mode) { switch (netdev->priv.ipvlan_attr.mode) {
case IPVLAN_MODE_L3: case IPVLAN_MODE_L3:
...@@ -5844,16 +5881,16 @@ static int get_config_net_ipvlan_isolation(const char *key, char *retv, int inle ...@@ -5844,16 +5881,16 @@ static int get_config_net_ipvlan_isolation(const char *key, char *retv, int inle
int len; int len;
const char *mode; const char *mode;
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_IPVLAN) if (netdev->type != LXC_NET_IPVLAN)
return 0; return ret_errno(EINVAL);
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
switch (netdev->priv.ipvlan_attr.isolation) { switch (netdev->priv.ipvlan_attr.isolation) {
case IPVLAN_ISOLATION_BRIDGE: case IPVLAN_ISOLATION_BRIDGE:
...@@ -5883,16 +5920,16 @@ static int get_config_net_veth_mode(const char *key, char *retv, int inlen, ...@@ -5883,16 +5920,16 @@ static int get_config_net_veth_mode(const char *key, char *retv, int inlen,
int len; int len;
const char *mode; const char *mode;
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VETH) if (netdev->type != LXC_NET_VETH)
return 0; return ret_errno(EINVAL);
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
switch (netdev->priv.veth_attr.mode) { switch (netdev->priv.veth_attr.mode) {
case VETH_MODE_BRIDGE: case VETH_MODE_BRIDGE:
...@@ -5918,16 +5955,16 @@ static int get_config_net_veth_pair(const char *key, char *retv, int inlen, ...@@ -5918,16 +5955,16 @@ static int get_config_net_veth_pair(const char *key, char *retv, int inlen,
int fulllen = 0; int fulllen = 0;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VETH) if (netdev->type != LXC_NET_VETH)
return 0; return ret_errno(EINVAL);
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
strprint(retv, inlen, "%s", strprint(retv, inlen, "%s",
netdev->priv.veth_attr.pair[0] != '\0' netdev->priv.veth_attr.pair[0] != '\0'
...@@ -5948,7 +5985,7 @@ static int get_config_net_veth_vlan_id(const char *key, char *retv, int inlen, ...@@ -5948,7 +5985,7 @@ static int get_config_net_veth_vlan_id(const char *key, char *retv, int inlen,
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VETH) if (netdev->type != LXC_NET_VETH)
return 0; return ret_errno(EINVAL);
if (!retv) if (!retv)
inlen = 0; inlen = 0;
...@@ -5960,8 +5997,9 @@ static int get_config_net_veth_vlan_id(const char *key, char *retv, int inlen, ...@@ -5960,8 +5997,9 @@ static int get_config_net_veth_vlan_id(const char *key, char *retv, int inlen,
return fulllen; return fulllen;
} }
static int get_config_net_veth_vlan_tagged_id(const char *key, char *retv, int inlen, static int get_config_net_veth_vlan_tagged_id(const char *key, char *retv,
struct lxc_conf *c, void *data) int inlen, struct lxc_conf *c,
void *data)
{ {
int len; int len;
size_t listlen; size_t listlen;
...@@ -5973,7 +6011,7 @@ static int get_config_net_veth_vlan_tagged_id(const char *key, char *retv, int i ...@@ -5973,7 +6011,7 @@ static int get_config_net_veth_vlan_tagged_id(const char *key, char *retv, int i
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VETH) if (netdev->type != LXC_NET_VETH)
return 0; return ret_errno(EINVAL);
if (!retv) if (!retv)
inlen = 0; inlen = 0;
...@@ -5984,8 +6022,7 @@ static int get_config_net_veth_vlan_tagged_id(const char *key, char *retv, int i ...@@ -5984,8 +6022,7 @@ static int get_config_net_veth_vlan_tagged_id(const char *key, char *retv, int i
lxc_list_for_each(it, &netdev->priv.veth_attr.vlan_tagged_ids) { lxc_list_for_each(it, &netdev->priv.veth_attr.vlan_tagged_ids) {
unsigned short i = PTR_TO_USHORT(it->elem); unsigned short i = PTR_TO_USHORT(it->elem);
strprint(retv, inlen, "%u%s", i, strprint(retv, inlen, "%u%s", i, (listlen-- > 1) ? "\n" : "");
(listlen-- > 1) ? "\n" : "");
} }
return fulllen; return fulllen;
...@@ -5998,14 +6035,14 @@ static int get_config_net_script_up(const char *key, char *retv, int inlen, ...@@ -5998,14 +6035,14 @@ static int get_config_net_script_up(const char *key, char *retv, int inlen,
int fulllen = 0; int fulllen = 0;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
if (!retv) if (!retv)
inlen = 0; inlen = 0;
else else
memset(retv, 0, inlen); memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
if (netdev->upscript) if (netdev->upscript)
strprint(retv, inlen, "%s", netdev->upscript); strprint(retv, inlen, "%s", netdev->upscript);
...@@ -6019,14 +6056,14 @@ static int get_config_net_script_down(const char *key, char *retv, int inlen, ...@@ -6019,14 +6056,14 @@ static int get_config_net_script_down(const char *key, char *retv, int inlen,
int fulllen = 0; int fulllen = 0;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
if (!retv) if (!retv)
inlen = 0; inlen = 0;
else else
memset(retv, 0, inlen); memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
if (netdev->downscript) if (netdev->downscript)
strprint(retv, inlen, "%s", netdev->downscript); strprint(retv, inlen, "%s", netdev->downscript);
...@@ -6040,14 +6077,14 @@ static int get_config_net_hwaddr(const char *key, char *retv, int inlen, ...@@ -6040,14 +6077,14 @@ static int get_config_net_hwaddr(const char *key, char *retv, int inlen,
int fulllen = 0; int fulllen = 0;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
if (!retv) if (!retv)
inlen = 0; inlen = 0;
else else
memset(retv, 0, inlen); memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
if (netdev->hwaddr) if (netdev->hwaddr)
strprint(retv, inlen, "%s", netdev->hwaddr); strprint(retv, inlen, "%s", netdev->hwaddr);
...@@ -6061,14 +6098,14 @@ static int get_config_net_mtu(const char *key, char *retv, int inlen, ...@@ -6061,14 +6098,14 @@ static int get_config_net_mtu(const char *key, char *retv, int inlen,
int fulllen = 0; int fulllen = 0;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
if (!retv) if (!retv)
inlen = 0; inlen = 0;
else else
memset(retv, 0, inlen); memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
if (netdev->mtu) if (netdev->mtu)
strprint(retv, inlen, "%s", netdev->mtu); strprint(retv, inlen, "%s", netdev->mtu);
...@@ -6082,16 +6119,16 @@ static int get_config_net_vlan_id(const char *key, char *retv, int inlen, ...@@ -6082,16 +6119,16 @@ static int get_config_net_vlan_id(const char *key, char *retv, int inlen,
int fulllen = 0; int fulllen = 0;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VLAN) if (netdev->type != LXC_NET_VLAN)
return 0; return ret_errno(EINVAL);
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
strprint(retv, inlen, "%d", netdev->priv.vlan_attr.vid); strprint(retv, inlen, "%d", netdev->priv.vlan_attr.vid);
...@@ -6106,14 +6143,14 @@ static int get_config_net_ipv4_gateway(const char *key, char *retv, int inlen, ...@@ -6106,14 +6143,14 @@ static int get_config_net_ipv4_gateway(const char *key, char *retv, int inlen,
int fulllen = 0; int fulllen = 0;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
if (!retv) if (!retv)
inlen = 0; inlen = 0;
else else
memset(retv, 0, inlen); memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
if (netdev->ipv4_gateway_auto) { if (netdev->ipv4_gateway_auto) {
strprint(retv, inlen, "auto"); strprint(retv, inlen, "auto");
} else if (netdev->ipv4_gateway_dev) { } else if (netdev->ipv4_gateway_dev) {
...@@ -6137,14 +6174,14 @@ static int get_config_net_ipv4_address(const char *key, char *retv, int inlen, ...@@ -6137,14 +6174,14 @@ static int get_config_net_ipv4_address(const char *key, char *retv, int inlen,
int fulllen = 0; int fulllen = 0;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
if (!retv) if (!retv)
inlen = 0; inlen = 0;
else else
memset(retv, 0, inlen); memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
listlen = lxc_list_len(&netdev->ipv4); listlen = lxc_list_len(&netdev->ipv4);
lxc_list_for_each(it, &netdev->ipv4) { lxc_list_for_each(it, &netdev->ipv4) {
...@@ -6168,16 +6205,16 @@ static int get_config_net_veth_ipv4_route(const char *key, char *retv, int inlen ...@@ -6168,16 +6205,16 @@ static int get_config_net_veth_ipv4_route(const char *key, char *retv, int inlen
int fulllen = 0; int fulllen = 0;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VETH) if (netdev->type != LXC_NET_VETH)
return 0; return ret_errno(EINVAL);
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
listlen = lxc_list_len(&netdev->priv.veth_attr.ipv4_routes); listlen = lxc_list_len(&netdev->priv.veth_attr.ipv4_routes);
...@@ -6200,14 +6237,14 @@ static int get_config_net_ipv6_gateway(const char *key, char *retv, int inlen, ...@@ -6200,14 +6237,14 @@ static int get_config_net_ipv6_gateway(const char *key, char *retv, int inlen,
int fulllen = 0; int fulllen = 0;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
if (!retv) if (!retv)
inlen = 0; inlen = 0;
else else
memset(retv, 0, inlen); memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
if (netdev->ipv6_gateway_auto) { if (netdev->ipv6_gateway_auto) {
strprint(retv, inlen, "auto"); strprint(retv, inlen, "auto");
} else if (netdev->ipv6_gateway_dev) { } else if (netdev->ipv6_gateway_dev) {
...@@ -6231,14 +6268,14 @@ static int get_config_net_ipv6_address(const char *key, char *retv, int inlen, ...@@ -6231,14 +6268,14 @@ static int get_config_net_ipv6_address(const char *key, char *retv, int inlen,
int fulllen = 0; int fulllen = 0;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (!netdev)
return ret_errno(EINVAL);
if (!retv) if (!retv)
inlen = 0; inlen = 0;
else else
memset(retv, 0, inlen); memset(retv, 0, inlen);
if (!netdev)
return ret_errno(EINVAL);
listlen = lxc_list_len(&netdev->ipv6); listlen = lxc_list_len(&netdev->ipv6);
lxc_list_for_each(it, &netdev->ipv6) { lxc_list_for_each(it, &netdev->ipv6) {
...@@ -6262,16 +6299,16 @@ static int get_config_net_veth_ipv6_route(const char *key, char *retv, int inlen ...@@ -6262,16 +6299,16 @@ static int get_config_net_veth_ipv6_route(const char *key, char *retv, int inlen
int fulllen = 0; int fulllen = 0;
struct lxc_netdev *netdev = data; struct lxc_netdev *netdev = data;
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
if (!netdev) if (!netdev)
return ret_errno(EINVAL); return ret_errno(EINVAL);
if (netdev->type != LXC_NET_VETH) if (netdev->type != LXC_NET_VETH)
return 0; return ret_errno(EINVAL);
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
listlen = lxc_list_len(&netdev->priv.veth_attr.ipv6_routes); listlen = lxc_list_len(&netdev->priv.veth_attr.ipv6_routes);
......
...@@ -481,6 +481,7 @@ void lxc_free_networks(struct lxc_list *networks) ...@@ -481,6 +481,7 @@ void lxc_free_networks(struct lxc_list *networks)
lxc_list_del(cur); lxc_list_del(cur);
lxc_free_netdev(netdev); lxc_free_netdev(netdev);
free(cur);
} }
/* prevent segfaults */ /* prevent segfaults */
......
...@@ -677,6 +677,8 @@ int lxc_safe_int64_residual(const char *numstr, int64_t *converted, int base, ch ...@@ -677,6 +677,8 @@ int lxc_safe_int64_residual(const char *numstr, int64_t *converted, int base, ch
if (!residual && residual_len != 0) if (!residual && residual_len != 0)
return ret_errno(EINVAL); return ret_errno(EINVAL);
memset(residual, 0, residual_len);
while (isspace(*numstr)) while (isspace(*numstr))
numstr++; numstr++;
...@@ -691,10 +693,8 @@ int lxc_safe_int64_residual(const char *numstr, int64_t *converted, int base, ch ...@@ -691,10 +693,8 @@ int lxc_safe_int64_residual(const char *numstr, int64_t *converted, int base, ch
if (residual) { if (residual) {
size_t len = 0; size_t len = 0;
if (*remaining == '\0') { if (*remaining == '\0')
memset(residual, 0, residual_len);
goto out; goto out;
}
len = strlen(remaining); len = strlen(remaining);
if (len >= residual_len) if (len >= residual_len)
......
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