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
63707931
Unverified
Commit
63707931
authored
Nov 29, 2017
by
Christian Brauner
Committed by
GitHub
Nov 29, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1955 from flx42/confile-fix-misc-issues
Fix errors in configuration file parsing
parents
242146d9
44047b2b
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
82 additions
and
58 deletions
+82
-58
confile.c
src/lxc/confile.c
+5
-1
confile_legacy.c
src/lxc/confile_legacy.c
+4
-0
confile_utils.c
src/lxc/confile_utils.c
+6
-51
log.c
src/lxc/log.c
+11
-0
lxc-test-utils.c
src/tests/lxc-test-utils.c
+24
-0
parse_config_file.c
src/tests/parse_config_file.c
+32
-6
No files found.
src/lxc/confile.c
View file @
63707931
...
...
@@ -2060,7 +2060,7 @@ static int parse_line(char *buffer, void *data)
}
if
(
empty_line
)
return
0
;
goto
on_error
;
line
+=
lxc_char_left_gc
(
line
,
strlen
(
line
));
...
...
@@ -3801,6 +3801,10 @@ static struct lxc_config_t *get_network_config_ops(const char *key,
/* lxc.net.<idx>.<subkey> */
if
(
idx_end
)
{
*
idx_end
=
'.'
;
if
(
strlen
(
idx_end
+
1
)
==
0
)
{
ERROR
(
"No subkey in network configuration key
\"
%s
\"
"
,
key
);
goto
on_error
;
}
memmove
(
copy
+
8
,
idx_end
+
1
,
strlen
(
idx_end
+
1
));
copy
[
strlen
(
key
)
-
numstrlen
+
1
]
=
'\0'
;
...
...
src/lxc/confile_legacy.c
View file @
63707931
...
...
@@ -90,6 +90,10 @@ int set_config_network_legacy_nic(const char *key, const char *value,
if
(
!
p
)
goto
out
;
if
(
strlen
(
p
+
1
)
==
0
)
{
ERROR
(
"No subkey in network configuration key
\"
%s
\"
"
,
key
);
goto
out
;
}
strcpy
(
copy
+
12
,
p
+
1
);
config
=
lxc_get_config
(
copy
);
if
(
!
config
)
{
...
...
src/lxc/confile_utils.c
View file @
63707931
...
...
@@ -545,63 +545,18 @@ int rand_complete_hwaddr(char *hwaddr)
bool
lxc_config_net_hwaddr
(
const
char
*
line
)
{
char
*
copy
,
*
p
;
unsigned
index
;
char
tmp
[
7
];
if
(
strncmp
(
line
,
"lxc.net"
,
7
)
!=
0
)
return
false
;
if
(
strncmp
(
line
,
"lxc.network.hwaddr"
,
18
)
==
0
)
return
true
;
/* We have to dup the line, if line is something like
* "lxc.net.[i].xxx = xxxxx ", we need to remove
* '[i]' and compare its key with 'lxc.net.hwaddr'*/
copy
=
strdup
(
line
);
if
(
!
copy
)
{
SYSERROR
(
"failed to allocate memory"
);
return
false
;
}
if
(
*
(
copy
+
8
)
>=
'0'
&&
*
(
copy
+
8
)
<=
'9'
)
{
p
=
strchr
(
copy
+
8
,
'.'
);
if
(
!
p
)
{
free
(
copy
);
return
false
;
}
/* strlen("hwaddr") = 6 */
if
(
strlen
(
p
+
1
)
>=
6
)
memmove
(
copy
+
8
,
p
+
1
,
6
);
copy
[
8
+
6
]
=
'\0'
;
}
if
(
strncmp
(
copy
,
"lxc.net.hwaddr"
,
14
)
==
0
)
{
free
(
copy
);
if
(
strncmp
(
line
,
"lxc.net.hwaddr"
,
14
)
==
0
)
return
true
;
}
free
(
copy
);
/* We have to dup the line second time, if line is something like
* "lxc.network.[i].xxx = xxxxx ", we need to remove
* '[i]' and compare its key with 'lxc.network.hwaddr'*/
copy
=
strdup
(
line
);
if
(
!
copy
)
{
SYSERROR
(
"failed to allocate memory"
);
return
false
;
}
if
(
*
(
copy
+
12
)
>=
'0'
&&
*
(
copy
+
12
)
<=
'9'
)
{
p
=
strchr
(
copy
+
12
,
'.'
);
if
(
!
p
)
{
free
(
copy
);
return
false
;
}
/* strlen("hwaddr") = 6 */
if
(
strlen
(
p
+
1
)
>=
6
)
memmove
(
copy
+
12
,
p
+
1
,
6
);
copy
[
12
+
6
]
=
'\0'
;
}
if
(
strncmp
(
copy
,
"lxc.network.hwaddr"
,
18
)
==
0
)
{
free
(
copy
);
if
(
strncmp
(
line
,
"lxc.network.hwaddr"
,
18
)
==
0
)
return
true
;
}
if
(
sscanf
(
line
,
"lxc.net.%u.%6s"
,
&
index
,
tmp
)
==
2
||
sscanf
(
line
,
"lxc.network.%u.%6s"
,
&
index
,
tmp
)
==
2
)
return
strncmp
(
tmp
,
"hwaddr"
,
6
)
==
0
;
free
(
copy
);
return
false
;
}
...
...
src/lxc/log.c
View file @
63707931
...
...
@@ -533,6 +533,17 @@ extern int lxc_log_syslog(int facility)
lxc_log_category_lxc
.
appender
=
&
log_appender_syslog
;
return
0
;
}
appender
=
lxc_log_category_lxc
.
appender
;
/* Check if syslog was already added, to avoid creating a loop */
while
(
appender
)
{
if
(
appender
==
&
log_appender_syslog
)
{
/* not an error: openlog re-opened the connection */
return
0
;
}
appender
=
appender
->
next
;
}
appender
=
lxc_log_category_lxc
.
appender
;
while
(
appender
->
next
!=
NULL
)
appender
=
appender
->
next
;
...
...
src/tests/lxc-test-utils.c
View file @
63707931
...
...
@@ -462,6 +462,29 @@ void test_parse_byte_size_string(void)
exit
(
EXIT_FAILURE
);
}
void
test_lxc_config_net_hwaddr
(
void
)
{
bool
lxc_config_net_hwaddr
(
const
char
*
line
);
if
(
!
lxc_config_net_hwaddr
(
"lxc.net.0.hwaddr = 00:16:3e:04:65:b8
\n
"
))
exit
(
EXIT_FAILURE
);
if
(
!
lxc_config_net_hwaddr
(
"lxc.network.hwaddr = 00:16:3e:04:65:b8
\n
"
))
exit
(
EXIT_FAILURE
);
if
(
!
lxc_config_net_hwaddr
(
"lxc.net.hwaddr = 00:16:3e:04:65:b8
\n
"
))
exit
(
EXIT_FAILURE
);
if
(
lxc_config_net_hwaddr
(
"lxc.net"
))
exit
(
EXIT_FAILURE
);
if
(
lxc_config_net_hwaddr
(
"lxc.net."
))
exit
(
EXIT_FAILURE
);
if
(
lxc_config_net_hwaddr
(
"lxc.net.0."
))
exit
(
EXIT_FAILURE
);
if
(
lxc_config_net_hwaddr
(
"lxc.network"
))
exit
(
EXIT_FAILURE
);
if
(
lxc_config_net_hwaddr
(
"lxc.network.0."
))
exit
(
EXIT_FAILURE
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
test_lxc_string_replace
();
...
...
@@ -472,6 +495,7 @@ int main(int argc, char *argv[])
test_lxc_safe_int
();
test_lxc_safe_long
();
test_parse_byte_size_string
();
test_lxc_config_net_hwaddr
();
exit
(
EXIT_SUCCESS
);
}
src/tests/parse_config_file.c
View file @
63707931
...
...
@@ -155,6 +155,33 @@ static int set_and_clear_complete_netdev(struct lxc_container *c)
return
0
;
}
static
int
set_invalid_netdev
(
struct
lxc_container
*
c
)
{
if
(
c
->
set_config_item
(
c
,
"lxc.net.0.asdf"
,
"veth"
))
{
lxc_error
(
"%s
\n
"
,
"lxc.net.0.asdf should be invalid"
);
return
-
1
;
}
if
(
c
->
set_config_item
(
c
,
"lxc.net.2147483647.type"
,
"veth"
))
{
lxc_error
(
"%s
\n
"
,
"lxc.net.2147483647.type should be invalid"
);
return
-
1
;
}
if
(
c
->
set_config_item
(
c
,
"lxc.net.0."
,
"veth"
))
{
lxc_error
(
"%s
\n
"
,
"lxc.net.0. should be invalid"
);
return
-
1
;
}
if
(
c
->
set_config_item
(
c
,
"lxc.network.0."
,
"veth"
))
{
lxc_error
(
"%s
\n
"
,
"lxc.network.0. should be invalid"
);
return
-
1
;
}
c
->
clear_config
(
c
);
c
->
lxc_conf
=
NULL
;
return
0
;
}
int
test_idmap_parser
(
void
)
{
size_t
i
;
...
...
@@ -970,12 +997,6 @@ int main(int argc, char *argv[])
goto
non_test_error
;
}
if
(
!
set_get_compare_clear_save_load
(
c
,
"lxc.net.0.asdf"
,
"veth"
,
tmpf
,
true
))
{
lxc_error
(
"%s
\n
"
,
"lxc.net.0.asdf"
);
goto
non_test_error
;
}
if
(
set_get_compare_clear_save_load_network
(
c
,
"lxc.net.0.macvlan.mode"
,
"private"
,
tmpf
,
true
,
"macvlan"
))
{
...
...
@@ -1070,6 +1091,11 @@ int main(int argc, char *argv[])
goto
non_test_error
;
}
if
(
set_invalid_netdev
(
c
)
<
0
)
{
lxc_error
(
"%s
\n
"
,
"failed to reject invalid configuration"
);
goto
non_test_error
;
}
ret
=
EXIT_SUCCESS
;
non_test_error:
(
void
)
unlink
(
tmpf
);
...
...
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