Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
cc98c470
Unverified
Commit
cc98c470
authored
Mar 27, 2021
by
Stéphane Graber
Committed by
GitHub
Mar 27, 2021
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3739 from brauner/2021-03-27/fixes
oss-fuzz: fixes
parents
6a374b65
b2606302
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
247 additions
and
194 deletions
+247
-194
cifuzz.yml
.github/workflows/cifuzz.yml
+1
-1
conf.c
src/lxc/conf.c
+25
-10
confile.c
src/lxc/confile.c
+217
-180
confile_utils.c
src/lxc/confile_utils.c
+1
-0
string_utils.c
src/lxc/string_utils.c
+3
-3
No files found.
.github/workflows/cifuzz.yml
View file @
cc98c470
...
...
@@ -29,7 +29,7 @@ jobs:
with
:
oss-fuzz-project-name
:
'
lxc'
fuzz-seconds
:
180
dry-run
:
true
dry-run
:
${{ matrix.sanitizer != 'address' }}
sanitizer
:
${{ matrix.sanitizer }}
-
name
:
Upload Crash
uses
:
actions/upload-artifact@v1
...
...
src/lxc/conf.c
View file @
cc98c470
...
...
@@ -3627,6 +3627,7 @@ int lxc_clear_config_caps(struct lxc_conf *c)
free
(
it
);
}
lxc_list_init
(
&
c
->
caps
);
return
0
;
}
...
...
@@ -3640,6 +3641,7 @@ static int lxc_free_idmap(struct lxc_list *id_map)
free
(
it
);
}
lxc_list_init
(
id_map
);
return
0
;
}
...
...
@@ -3666,16 +3668,15 @@ int lxc_clear_config_keepcaps(struct lxc_conf *c)
free
(
it
);
}
lxc_list_init
(
&
c
->
keepcaps
);
return
0
;
}
int
lxc_clear_namespace
(
struct
lxc_conf
*
c
)
{
int
i
;
for
(
i
=
0
;
i
<
LXC_NS_MAX
;
i
++
)
{
free
(
c
->
ns_share
[
i
]);
c
->
ns_share
[
i
]
=
NULL
;
}
for
(
int
i
=
0
;
i
<
LXC_NS_MAX
;
i
++
)
free_disarm
(
c
->
ns_share
[
i
]);
return
0
;
}
...
...
@@ -3708,7 +3709,7 @@ int lxc_clear_cgroups(struct lxc_conf *c, const char *key, int version)
else
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
;
if
(
!
all
&&
!
strequal
(
cg
->
subsystem
,
k
))
...
...
@@ -3721,6 +3722,9 @@ int lxc_clear_cgroups(struct lxc_conf *c, const char *key, int version)
free
(
it
);
}
if
(
all
)
lxc_list_init
(
list
);
return
0
;
}
...
...
@@ -3808,7 +3812,7 @@ int lxc_clear_procs(struct lxc_conf *c, const char *key)
else
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
;
if
(
!
all
&&
!
strequal
(
proc
->
filename
,
k
))
...
...
@@ -3821,6 +3825,9 @@ int lxc_clear_procs(struct lxc_conf *c, const char *key)
free
(
it
);
}
if
(
all
)
lxc_list_init
(
&
c
->
procs
);
return
0
;
}
...
...
@@ -3834,6 +3841,7 @@ int lxc_clear_groups(struct lxc_conf *c)
free
(
it
);
}
lxc_list_init
(
&
c
->
groups
);
return
0
;
}
...
...
@@ -3847,6 +3855,7 @@ int lxc_clear_environment(struct lxc_conf *c)
free
(
it
);
}
lxc_list_init
(
&
c
->
environment
);
return
0
;
}
...
...
@@ -3860,6 +3869,7 @@ int lxc_clear_mount_entries(struct lxc_conf *c)
free
(
it
);
}
lxc_list_init
(
&
c
->
mount_list
);
return
0
;
}
...
...
@@ -3871,7 +3881,6 @@ int lxc_clear_automounts(struct lxc_conf *c)
int
lxc_clear_hooks
(
struct
lxc_conf
*
c
,
const
char
*
key
)
{
int
i
;
struct
lxc_list
*
it
,
*
next
;
const
char
*
k
=
NULL
;
bool
all
=
false
,
done
=
false
;
...
...
@@ -3883,13 +3892,14 @@ int lxc_clear_hooks(struct lxc_conf *c, const char *key)
else
return
-
1
;
for
(
i
=
0
;
i
<
NUM_LXC_HOOKS
;
i
++
)
{
for
(
i
nt
i
=
0
;
i
<
NUM_LXC_HOOKS
;
i
++
)
{
if
(
all
||
strequal
(
k
,
lxchook_names
[
i
]))
{
lxc_list_for_each_safe
(
it
,
&
c
->
hooks
[
i
],
next
)
{
lxc_list_del
(
it
);
free
(
it
->
elem
);
free
(
it
);
}
lxc_list_init
(
&
c
->
hooks
[
i
]);
done
=
true
;
}
...
...
@@ -3910,17 +3920,21 @@ static inline void lxc_clear_aliens(struct lxc_conf *conf)
free
(
it
->
elem
);
free
(
it
);
}
lxc_list_init
(
&
conf
->
aliens
);
}
void
lxc_clear_includes
(
struct
lxc_conf
*
conf
)
{
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
);
free
(
it
->
elem
);
free
(
it
);
}
lxc_list_init
(
&
conf
->
includes
);
}
int
lxc_clear_apparmor_raw
(
struct
lxc_conf
*
c
)
...
...
@@ -3933,6 +3947,7 @@ int lxc_clear_apparmor_raw(struct lxc_conf *c)
free
(
it
);
}
lxc_list_init
(
&
c
->
lsm_aa_raw
);
return
0
;
}
...
...
src/lxc/confile.c
View file @
cc98c470
...
...
@@ -321,12 +321,12 @@ static int set_config_net_type(const char *key, const char *value,
{
struct
lxc_netdev
*
netdev
=
data
;
if
(
lxc_config_value_empty
(
value
))
return
clr_config_net_type
(
key
,
lxc_conf
,
data
);
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
if
(
lxc_config_value_empty
(
value
))
return
clr_config_net_type
(
key
,
lxc_conf
,
data
);
if
(
strequal
(
value
,
"veth"
))
{
netdev
->
type
=
LXC_NET_VETH
;
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,
{
struct
lxc_netdev
*
netdev
=
data
;
if
(
lxc_config_value_empty
(
value
))
return
clr_config_net_flags
(
key
,
lxc_conf
,
data
);
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
if
(
lxc_config_value_empty
(
value
))
return
clr_config_net_flags
(
key
,
lxc_conf
,
data
);
netdev
->
flags
|=
IFF_UP
;
return
0
;
...
...
@@ -422,12 +422,12 @@ static int set_config_net_link(const char *key, const char *value,
struct
lxc_netdev
*
netdev
=
data
;
int
ret
=
0
;
if
(
lxc_config_value_empty
(
value
))
return
clr_config_net_link
(
key
,
lxc_conf
,
data
);
if
(
!
netdev
)
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
)
ret
=
create_matched_ifnames
(
value
,
lxc_conf
,
netdev
);
else
...
...
@@ -443,12 +443,12 @@ static int set_config_net_l2proxy(const char *key, const char *value,
unsigned
int
val
=
0
;
int
ret
;
if
(
lxc_config_value_empty
(
value
))
return
clr_config_net_l2proxy
(
key
,
lxc_conf
,
data
);
if
(
!
netdev
)
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
);
if
(
ret
<
0
)
return
ret_errno
(
ret
);
...
...
@@ -470,12 +470,12 @@ static int set_config_net_name(const char *key, const char *value,
{
struct
lxc_netdev
*
netdev
=
data
;
if
(
lxc_config_value_empty
(
value
))
return
clr_config_net_name
(
key
,
lxc_conf
,
data
);
if
(
!
netdev
)
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
));
}
...
...
@@ -485,6 +485,12 @@ static int set_config_net_veth_mode(const char *key, const char *value,
{
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
))
return
clr_config_net_veth_mode
(
key
,
lxc_conf
,
data
);
...
...
@@ -499,18 +505,21 @@ static int set_config_net_veth_pair(const char *key, const char *value,
{
struct
lxc_netdev
*
netdev
=
data
;
if
(
lxc_config_value_empty
(
value
))
return
clr_config_net_veth_pair
(
key
,
lxc_conf
,
data
);
if
(
!
netdev
)
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
,
sizeof
(
netdev
->
priv
.
veth_attr
.
pair
));
}
static
int
set_config_net_veth_vlan_id
(
const
char
*
key
,
const
char
*
value
,
struct
lxc_conf
*
lxc_conf
,
void
*
data
)
struct
lxc_conf
*
lxc_conf
,
void
*
data
)
{
int
ret
;
struct
lxc_netdev
*
netdev
=
data
;
...
...
@@ -518,6 +527,9 @@ static int set_config_net_veth_vlan_id(const char *key, const char *value,
if
(
!
netdev
)
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_vlan_id
(
key
,
lxc_conf
,
data
);
...
...
@@ -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
,
struct
lxc_conf
*
lxc_conf
,
void
*
data
)
struct
lxc_conf
*
lxc_conf
,
void
*
data
)
{
__do_free
struct
lxc_list
*
list
=
NULL
;
int
ret
;
...
...
@@ -551,6 +564,9 @@ static int set_config_net_veth_vlan_tagged_id(const char *key, const char *value
if
(
!
netdev
)
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_vlan_tagged_id
(
key
,
lxc_conf
,
data
);
...
...
@@ -577,49 +593,48 @@ static int set_config_net_macvlan_mode(const char *key, const char *value,
{
struct
lxc_netdev
*
netdev
=
data
;
if
(
lxc_config_value_empty
(
value
))
return
clr_config_net_macvlan_mode
(
key
,
lxc_conf
,
data
);
if
(
!
netdev
)
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
);
}
static
int
set_config_net_ipvlan_mode
(
const
char
*
key
,
const
char
*
value
,
struct
lxc_conf
*
lxc_conf
,
void
*
data
)
struct
lxc_conf
*
lxc_conf
,
void
*
data
)
{
struct
lxc_netdev
*
netdev
=
data
;
if
(
lxc_config_value_empty
(
value
))
return
clr_config_net_ipvlan_mode
(
key
,
lxc_conf
,
data
);
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
if
(
netdev
->
type
!=
LXC_NET_IPVLAN
)
return
log_error_errno
(
-
EINVAL
,
EINVAL
,
"Invalid ipvlan mode
\"
%s
\"
, can only be used with ipvlan network"
,
value
);
return
syserror_set
(
-
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
);
}
static
int
set_config_net_ipvlan_isolation
(
const
char
*
key
,
const
char
*
value
,
struct
lxc_conf
*
lxc_conf
,
void
*
data
)
struct
lxc_conf
*
lxc_conf
,
void
*
data
)
{
struct
lxc_netdev
*
netdev
=
data
;
if
(
lxc_config_value_empty
(
value
))
return
clr_config_net_ipvlan_isolation
(
key
,
lxc_conf
,
data
);
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
if
(
netdev
->
type
!=
LXC_NET_IPVLAN
)
return
log_error_errno
(
-
EINVAL
,
EINVAL
,
"Invalid ipvlan isolation
\"
%s
\"
, can only be used with ipvlan network"
,
value
);
return
syserror_set
(
-
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
);
}
...
...
@@ -630,21 +645,20 @@ static int set_config_net_hwaddr(const char *key, const char *value,
__do_free
char
*
new_value
=
NULL
;
struct
lxc_netdev
*
netdev
=
data
;
if
(
lxc_config_value_empty
(
value
))
return
clr_config_net_hwaddr
(
key
,
lxc_conf
,
data
);
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
if
(
lxc_config_value_empty
(
value
))
return
clr_config_net_hwaddr
(
key
,
lxc_conf
,
data
);
new_value
=
strdup
(
value
);
if
(
!
new_value
)
return
ret_errno
(
ENOMEM
);
rand_complete_hwaddr
(
new_value
);
if
(
lxc_config_value_empty
(
new_value
))
free_disarm
(
netdev
->
hwaddr
);
else
free_disarm
(
netdev
->
hwaddr
);
if
(
!
lxc_config_value_empty
(
new_value
))
netdev
->
hwaddr
=
move_ptr
(
new_value
);
return
0
;
...
...
@@ -656,12 +670,15 @@ static int set_config_net_vlan_id(const char *key, const char *value,
int
ret
;
struct
lxc_netdev
*
netdev
=
data
;
if
(
lxc_config_value_empty
(
value
))
return
clr_config_net_vlan_id
(
key
,
lxc_conf
,
data
);
if
(
!
netdev
)
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
);
if
(
ret
<
0
)
return
ret
;
...
...
@@ -674,12 +691,12 @@ static int set_config_net_mtu(const char *key, const char *value,
{
struct
lxc_netdev
*
netdev
=
data
;
if
(
lxc_config_value_empty
(
value
))
return
clr_config_net_mtu
(
key
,
lxc_conf
,
data
);
if
(
!
netdev
)
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
);
}
...
...
@@ -694,12 +711,12 @@ static int set_config_net_ipv4_address(const char *key, const char *value,
char
*
cursor
,
*
slash
;
char
*
bcast
=
NULL
,
*
prefix
=
NULL
;
if
(
lxc_config_value_empty
(
value
))
return
clr_config_net_ipv4_address
(
key
,
lxc_conf
,
data
);
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
if
(
lxc_config_value_empty
(
value
))
return
clr_config_net_ipv4_address
(
key
,
lxc_conf
,
data
);
inetdev
=
zalloc
(
sizeof
(
*
inetdev
));
if
(
!
inetdev
)
return
ret_errno
(
ENOMEM
);
...
...
@@ -765,12 +782,12 @@ static int set_config_net_ipv4_gateway(const char *key, const char *value,
{
struct
lxc_netdev
*
netdev
=
data
;
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
if
(
lxc_config_value_empty
(
value
))
return
clr_config_net_ipv4_gateway
(
key
,
lxc_conf
,
data
);
if
(
!
netdev
)
return
-
1
;
free
(
netdev
->
ipv4_gateway
);
if
(
strequal
(
value
,
"auto"
))
{
...
...
@@ -800,7 +817,7 @@ static int set_config_net_ipv4_gateway(const char *key, const char *value,
}
static
int
set_config_net_veth_ipv4_route
(
const
char
*
key
,
const
char
*
value
,
struct
lxc_conf
*
lxc_conf
,
void
*
data
)
struct
lxc_conf
*
lxc_conf
,
void
*
data
)
{
__do_free
char
*
valdup
=
NULL
;
__do_free
struct
lxc_inetdev
*
inetdev
=
NULL
;
...
...
@@ -809,16 +826,14 @@ static int set_config_net_veth_ipv4_route(const char *key, const char *value,
char
*
netmask
,
*
slash
;
struct
lxc_netdev
*
netdev
=
data
;
if
(
lxc_config_value_empty
(
value
))
return
clr_config_net_veth_ipv4_route
(
key
,
lxc_conf
,
data
);
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
if
(
netdev
->
type
!=
LXC_NET_VETH
)
return
log_error_errno
(
-
EINVAL
,
EINVAL
,
"Invalid ipv4 route
\"
%s
\"
, can only be used with veth network"
,
value
);
return
syserror_set
(
-
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
));
if
(
!
inetdev
)
...
...
@@ -870,12 +885,12 @@ static int set_config_net_ipv6_address(const char *key, const char *value,
struct
lxc_netdev
*
netdev
=
data
;
char
*
slash
,
*
netmask
;
if
(
lxc_config_value_empty
(
value
))
return
clr_config_net_ipv6_address
(
key
,
lxc_conf
,
data
);
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
if
(
lxc_config_value_empty
(
value
))
return
clr_config_net_ipv6_address
(
key
,
lxc_conf
,
data
);
inet6dev
=
zalloc
(
sizeof
(
*
inet6dev
));
if
(
!
inet6dev
)
return
ret_errno
(
ENOMEM
);
...
...
@@ -916,12 +931,12 @@ static int set_config_net_ipv6_gateway(const char *key, const char *value,
{
struct
lxc_netdev
*
netdev
=
data
;
if
(
lxc_config_value_empty
(
value
))
return
clr_config_net_ipv6_gateway
(
key
,
lxc_conf
,
data
);
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
if
(
lxc_config_value_empty
(
value
))
return
clr_config_net_ipv6_gateway
(
key
,
lxc_conf
,
data
);
free
(
netdev
->
ipv6_gateway
);
if
(
strequal
(
value
,
"auto"
))
{
...
...
@@ -952,7 +967,7 @@ static int set_config_net_ipv6_gateway(const char *key, const char *value,
}
static
int
set_config_net_veth_ipv6_route
(
const
char
*
key
,
const
char
*
value
,
struct
lxc_conf
*
lxc_conf
,
void
*
data
)
struct
lxc_conf
*
lxc_conf
,
void
*
data
)
{
__do_free
char
*
valdup
=
NULL
;
__do_free
struct
lxc_inet6dev
*
inet6dev
=
NULL
;
...
...
@@ -961,16 +976,14 @@ static int set_config_net_veth_ipv6_route(const char *key, const char *value,
char
*
netmask
,
*
slash
;
struct
lxc_netdev
*
netdev
=
data
;
if
(
lxc_config_value_empty
(
value
))
return
clr_config_net_veth_ipv6_route
(
key
,
lxc_conf
,
data
);
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
if
(
netdev
->
type
!=
LXC_NET_VETH
)
return
log_error_errno
(
-
EINVAL
,
EINVAL
,
"Invalid ipv6 route
\"
%s
\"
, can only be used with veth network"
,
value
);
return
syserror_set
(
-
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
));
if
(
!
inet6dev
)
...
...
@@ -1016,12 +1029,12 @@ static int set_config_net_script_up(const char *key, const char *value,
{
struct
lxc_netdev
*
netdev
=
data
;
if
(
lxc_config_value_empty
(
value
))
return
clr_config_net_script_up
(
key
,
lxc_conf
,
data
);
if
(
!
netdev
)
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
);
}
...
...
@@ -1030,12 +1043,12 @@ static int set_config_net_script_down(const char *key, const char *value,
{
struct
lxc_netdev
*
netdev
=
data
;
if
(
lxc_config_value_empty
(
value
))
return
clr_config_net_script_down
(
key
,
lxc_conf
,
data
);
if
(
!
netdev
)
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
);
}
...
...
@@ -5171,7 +5184,7 @@ static struct lxc_config_t *get_network_config_ops(const char *key,
char
*
idx_start
,
*
idx_end
;
/* 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
);
copy
=
strdup
(
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
);
/* 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
);
/* beginning of index string */
idx_start
=
(
copy
+
7
);
idx_start
=
copy
+
(
STRLITERALLEN
(
"lxc.net."
)
-
1
);
*
idx_start
=
'\0'
;
/* end of index string */
idx_end
=
strchr
((
copy
+
8
),
'.'
);
idx_end
=
strchr
((
copy
+
STRLITERALLEN
(
"lxc.net."
)
),
'.'
);
if
(
idx_end
)
*
idx_end
=
'\0'
;
...
...
@@ -5202,7 +5215,7 @@ static struct lxc_config_t *get_network_config_ops(const char *key,
* better safe than sorry.
* (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"
);
*
idx
=
tmpidx
;
...
...
@@ -5216,8 +5229,10 @@ static struct lxc_config_t *get_network_config_ops(const char *key,
*
idx_end
=
'.'
;
if
(
strlen
(
idx_end
+
1
)
==
0
)
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'
;
config
=
lxc_get_config
(
copy
);
...
...
@@ -5402,7 +5417,7 @@ static int clr_config_net_ipvlan_mode(const char *key,
}
static
int
clr_config_net_ipvlan_isolation
(
const
char
*
key
,
struct
lxc_conf
*
lxc_conf
,
void
*
data
)
struct
lxc_conf
*
lxc_conf
,
void
*
data
)
{
struct
lxc_netdev
*
netdev
=
data
;
...
...
@@ -5441,6 +5456,9 @@ static int clr_config_net_veth_pair(const char *key, struct lxc_conf *lxc_conf,
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
if
(
netdev
->
type
!=
LXC_NET_VETH
)
return
0
;
netdev
->
priv
.
veth_attr
.
pair
[
0
]
=
'\0'
;
return
0
;
...
...
@@ -5454,6 +5472,9 @@ static int clr_config_net_veth_vlan_id(const char *key, struct lxc_conf *lxc_con
if
(
!
netdev
)
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_set
=
false
;
...
...
@@ -5469,6 +5490,9 @@ static int clr_config_net_veth_vlan_tagged_id(const char *key,
if
(
!
netdev
)
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_del
(
cur
);
free
(
cur
);
...
...
@@ -5538,6 +5562,9 @@ static int clr_config_net_vlan_id(const char *key, struct lxc_conf *lxc_conf,
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
if
(
netdev
->
type
!=
LXC_NET_VLAN
)
return
0
;
netdev
->
priv
.
vlan_attr
.
vid
=
0
;
return
0
;
...
...
@@ -5583,6 +5610,9 @@ static int clr_config_net_veth_ipv4_route(const char *key,
if
(
!
netdev
)
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_del
(
cur
);
free
(
cur
->
elem
);
...
...
@@ -5632,6 +5662,9 @@ static int clr_config_net_veth_ipv6_route(const char *key,
if
(
!
netdev
)
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_del
(
cur
);
free
(
cur
->
elem
);
...
...
@@ -5672,14 +5705,14 @@ static int get_config_net_type(const char *key, char *retv, int inlen,
int
fulllen
=
0
;
struct
lxc_netdev
*
netdev
=
data
;
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
if
(
!
retv
)
inlen
=
0
;
else
memset
(
retv
,
0
,
inlen
);
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
strprint
(
retv
,
inlen
,
"%s"
,
lxc_net_type_to_str
(
netdev
->
type
));
return
fulllen
;
...
...
@@ -5692,14 +5725,14 @@ static int get_config_net_flags(const char *key, char *retv, int inlen,
int
fulllen
=
0
;
struct
lxc_netdev
*
netdev
=
data
;
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
if
(
!
retv
)
inlen
=
0
;
else
memset
(
retv
,
0
,
inlen
);
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
if
(
netdev
->
flags
&
IFF_UP
)
strprint
(
retv
,
inlen
,
"up"
);
...
...
@@ -5713,14 +5746,14 @@ static int get_config_net_link(const char *key, char *retv, int inlen,
int
fulllen
=
0
;
struct
lxc_netdev
*
netdev
=
data
;
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
if
(
!
retv
)
inlen
=
0
;
else
memset
(
retv
,
0
,
inlen
);
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
if
(
netdev
->
link
[
0
]
!=
'\0'
)
strprint
(
retv
,
inlen
,
"%s"
,
netdev
->
link
);
...
...
@@ -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_netdev
*
netdev
=
data
;
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
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,
int
fulllen
=
0
;
struct
lxc_netdev
*
netdev
=
data
;
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
if
(
!
retv
)
inlen
=
0
;
else
memset
(
retv
,
0
,
inlen
);
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
if
(
netdev
->
name
[
0
]
!=
'\0'
)
strprint
(
retv
,
inlen
,
"%s"
,
netdev
->
name
);
...
...
@@ -5763,16 +5800,16 @@ static int get_config_net_macvlan_mode(const char *key, char *retv, int inlen,
const
char
*
mode
;
struct
lxc_netdev
*
netdev
=
data
;
if
(
!
retv
)
inlen
=
0
;
else
memset
(
retv
,
0
,
inlen
);
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
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
)
{
case
MACVLAN_MODE_PRIVATE
:
...
...
@@ -5805,16 +5842,16 @@ static int get_config_net_ipvlan_mode(const char *key, char *retv, int inlen,
int
len
;
const
char
*
mode
;
if
(
!
retv
)
inlen
=
0
;
else
memset
(
retv
,
0
,
inlen
);
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
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
)
{
case
IPVLAN_MODE_L3
:
...
...
@@ -5844,16 +5881,16 @@ static int get_config_net_ipvlan_isolation(const char *key, char *retv, int inle
int
len
;
const
char
*
mode
;
if
(
!
retv
)
inlen
=
0
;
else
memset
(
retv
,
0
,
inlen
);
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
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
)
{
case
IPVLAN_ISOLATION_BRIDGE
:
...
...
@@ -5876,23 +5913,23 @@ static int get_config_net_ipvlan_isolation(const char *key, char *retv, int inle
}
static
int
get_config_net_veth_mode
(
const
char
*
key
,
char
*
retv
,
int
inlen
,
struct
lxc_conf
*
c
,
void
*
data
)
struct
lxc_conf
*
c
,
void
*
data
)
{
int
fulllen
=
0
;
struct
lxc_netdev
*
netdev
=
data
;
int
len
;
const
char
*
mode
;
if
(
!
retv
)
inlen
=
0
;
else
memset
(
retv
,
0
,
inlen
);
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
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
)
{
case
VETH_MODE_BRIDGE
:
...
...
@@ -5918,16 +5955,16 @@ static int get_config_net_veth_pair(const char *key, char *retv, int inlen,
int
fulllen
=
0
;
struct
lxc_netdev
*
netdev
=
data
;
if
(
!
retv
)
inlen
=
0
;
else
memset
(
retv
,
0
,
inlen
);
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
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"
,
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,
return
ret_errno
(
EINVAL
);
if
(
netdev
->
type
!=
LXC_NET_VETH
)
return
0
;
return
ret_errno
(
EINVAL
)
;
if
(
!
retv
)
inlen
=
0
;
...
...
@@ -5960,8 +5997,9 @@ static int get_config_net_veth_vlan_id(const char *key, char *retv, int inlen,
return
fulllen
;
}
static
int
get_config_net_veth_vlan_tagged_id
(
const
char
*
key
,
char
*
retv
,
int
inlen
,
struct
lxc_conf
*
c
,
void
*
data
)
static
int
get_config_net_veth_vlan_tagged_id
(
const
char
*
key
,
char
*
retv
,
int
inlen
,
struct
lxc_conf
*
c
,
void
*
data
)
{
int
len
;
size_t
listlen
;
...
...
@@ -5973,7 +6011,7 @@ static int get_config_net_veth_vlan_tagged_id(const char *key, char *retv, int i
return
ret_errno
(
EINVAL
);
if
(
netdev
->
type
!=
LXC_NET_VETH
)
return
0
;
return
ret_errno
(
EINVAL
)
;
if
(
!
retv
)
inlen
=
0
;
...
...
@@ -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
)
{
unsigned
short
i
=
PTR_TO_USHORT
(
it
->
elem
);
strprint
(
retv
,
inlen
,
"%u%s"
,
i
,
(
listlen
--
>
1
)
?
"
\n
"
:
""
);
strprint
(
retv
,
inlen
,
"%u%s"
,
i
,
(
listlen
--
>
1
)
?
"
\n
"
:
""
);
}
return
fulllen
;
...
...
@@ -5998,14 +6035,14 @@ static int get_config_net_script_up(const char *key, char *retv, int inlen,
int
fulllen
=
0
;
struct
lxc_netdev
*
netdev
=
data
;
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
if
(
!
retv
)
inlen
=
0
;
else
memset
(
retv
,
0
,
inlen
);
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
if
(
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,
int
fulllen
=
0
;
struct
lxc_netdev
*
netdev
=
data
;
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
if
(
!
retv
)
inlen
=
0
;
else
memset
(
retv
,
0
,
inlen
);
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
if
(
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,
int
fulllen
=
0
;
struct
lxc_netdev
*
netdev
=
data
;
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
if
(
!
retv
)
inlen
=
0
;
else
memset
(
retv
,
0
,
inlen
);
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
if
(
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,
int
fulllen
=
0
;
struct
lxc_netdev
*
netdev
=
data
;
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
if
(
!
retv
)
inlen
=
0
;
else
memset
(
retv
,
0
,
inlen
);
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
if
(
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,
int
fulllen
=
0
;
struct
lxc_netdev
*
netdev
=
data
;
if
(
!
retv
)
inlen
=
0
;
else
memset
(
retv
,
0
,
inlen
);
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
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
);
...
...
@@ -6106,14 +6143,14 @@ static int get_config_net_ipv4_gateway(const char *key, char *retv, int inlen,
int
fulllen
=
0
;
struct
lxc_netdev
*
netdev
=
data
;
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
if
(
!
retv
)
inlen
=
0
;
else
memset
(
retv
,
0
,
inlen
);
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
if
(
netdev
->
ipv4_gateway_auto
)
{
strprint
(
retv
,
inlen
,
"auto"
);
}
else
if
(
netdev
->
ipv4_gateway_dev
)
{
...
...
@@ -6137,14 +6174,14 @@ static int get_config_net_ipv4_address(const char *key, char *retv, int inlen,
int
fulllen
=
0
;
struct
lxc_netdev
*
netdev
=
data
;
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
if
(
!
retv
)
inlen
=
0
;
else
memset
(
retv
,
0
,
inlen
);
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
listlen
=
lxc_list_len
(
&
netdev
->
ipv4
);
lxc_list_for_each
(
it
,
&
netdev
->
ipv4
)
{
...
...
@@ -6159,7 +6196,7 @@ static int get_config_net_ipv4_address(const char *key, char *retv, int inlen,
}
static
int
get_config_net_veth_ipv4_route
(
const
char
*
key
,
char
*
retv
,
int
inlen
,
struct
lxc_conf
*
c
,
void
*
data
)
struct
lxc_conf
*
c
,
void
*
data
)
{
int
len
;
size_t
listlen
;
...
...
@@ -6168,16 +6205,16 @@ static int get_config_net_veth_ipv4_route(const char *key, char *retv, int inlen
int
fulllen
=
0
;
struct
lxc_netdev
*
netdev
=
data
;
if
(
!
retv
)
inlen
=
0
;
else
memset
(
retv
,
0
,
inlen
);
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
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
);
...
...
@@ -6200,14 +6237,14 @@ static int get_config_net_ipv6_gateway(const char *key, char *retv, int inlen,
int
fulllen
=
0
;
struct
lxc_netdev
*
netdev
=
data
;
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
if
(
!
retv
)
inlen
=
0
;
else
memset
(
retv
,
0
,
inlen
);
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
if
(
netdev
->
ipv6_gateway_auto
)
{
strprint
(
retv
,
inlen
,
"auto"
);
}
else
if
(
netdev
->
ipv6_gateway_dev
)
{
...
...
@@ -6231,14 +6268,14 @@ static int get_config_net_ipv6_address(const char *key, char *retv, int inlen,
int
fulllen
=
0
;
struct
lxc_netdev
*
netdev
=
data
;
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
if
(
!
retv
)
inlen
=
0
;
else
memset
(
retv
,
0
,
inlen
);
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
listlen
=
lxc_list_len
(
&
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
int
fulllen
=
0
;
struct
lxc_netdev
*
netdev
=
data
;
if
(
!
retv
)
inlen
=
0
;
else
memset
(
retv
,
0
,
inlen
);
if
(
!
netdev
)
return
ret_errno
(
EINVAL
);
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
);
...
...
src/lxc/confile_utils.c
View file @
cc98c470
...
...
@@ -481,6 +481,7 @@ void lxc_free_networks(struct lxc_list *networks)
lxc_list_del
(
cur
);
lxc_free_netdev
(
netdev
);
free
(
cur
);
}
/* prevent segfaults */
...
...
src/lxc/string_utils.c
View file @
cc98c470
...
...
@@ -677,6 +677,8 @@ int lxc_safe_int64_residual(const char *numstr, int64_t *converted, int base, ch
if
(
!
residual
&&
residual_len
!=
0
)
return
ret_errno
(
EINVAL
);
memset
(
residual
,
0
,
residual_len
);
while
(
isspace
(
*
numstr
))
numstr
++
;
...
...
@@ -691,10 +693,8 @@ int lxc_safe_int64_residual(const char *numstr, int64_t *converted, int base, ch
if
(
residual
)
{
size_t
len
=
0
;
if
(
*
remaining
==
'\0'
)
{
memset
(
residual
,
0
,
residual_len
);
if
(
*
remaining
==
'\0'
)
goto
out
;
}
len
=
strlen
(
remaining
);
if
(
len
>=
residual_len
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment