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
d3435415
Unverified
Commit
d3435415
authored
Mar 16, 2018
by
Christian Brauner
Committed by
GitHub
Mar 16, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2223 from flx42/fix-lxc-execute-use-after-free
tools: fix container use-after-free
parents
4edd0ba7
020c90b7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
43 deletions
+31
-43
lxc_execute.c
src/lxc/tools/lxc_execute.c
+31
-43
No files found.
src/lxc/tools/lxc_execute.c
View file @
d3435415
...
@@ -138,16 +138,17 @@ int main(int argc, char *argv[])
...
@@ -138,16 +138,17 @@ int main(int argc, char *argv[])
{
{
struct
lxc_container
*
c
;
struct
lxc_container
*
c
;
struct
lxc_log
log
;
struct
lxc_log
log
;
int
err
=
EXIT_FAILURE
;
int
ret
;
int
ret
;
bool
bret
;
bool
bret
;
lxc_list_init
(
&
defines
);
lxc_list_init
(
&
defines
);
if
(
lxc_caps_init
())
if
(
lxc_caps_init
())
exit
(
EXIT_FAILURE
);
exit
(
err
);
if
(
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
))
if
(
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
))
exit
(
EXIT_FAILURE
);
exit
(
err
);
log
.
name
=
my_args
.
name
;
log
.
name
=
my_args
.
name
;
log
.
file
=
my_args
.
log_file
;
log
.
file
=
my_args
.
log_file
;
...
@@ -157,102 +158,89 @@ int main(int argc, char *argv[])
...
@@ -157,102 +158,89 @@ int main(int argc, char *argv[])
log
.
lxcpath
=
my_args
.
lxcpath
[
0
];
log
.
lxcpath
=
my_args
.
lxcpath
[
0
];
if
(
lxc_log_init
(
&
log
))
if
(
lxc_log_init
(
&
log
))
exit
(
EXIT_FAILURE
);
exit
(
err
);
c
=
lxc_container_new
(
my_args
.
name
,
my_args
.
lxcpath
[
0
]);
c
=
lxc_container_new
(
my_args
.
name
,
my_args
.
lxcpath
[
0
]);
if
(
!
c
)
{
if
(
!
c
)
{
fprintf
(
stderr
,
"Failed to create lxc_container
\n
"
);
fprintf
(
stderr
,
"Failed to create lxc_container
\n
"
);
exit
(
EXIT_FAILURE
);
exit
(
err
);
}
}
if
(
my_args
.
rcfile
)
{
if
(
my_args
.
rcfile
)
{
c
->
clear_config
(
c
);
c
->
clear_config
(
c
);
if
(
!
c
->
load_config
(
c
,
my_args
.
rcfile
))
{
if
(
!
c
->
load_config
(
c
,
my_args
.
rcfile
))
{
fprintf
(
stderr
,
"Failed to load rcfile
\n
"
);
fprintf
(
stderr
,
"Failed to load rcfile
\n
"
);
lxc_container_put
(
c
);
goto
out
;
exit
(
EXIT_FAILURE
);
}
}
c
->
configfile
=
strdup
(
my_args
.
rcfile
);
c
->
configfile
=
strdup
(
my_args
.
rcfile
);
if
(
!
c
->
configfile
)
{
if
(
!
c
->
configfile
)
{
fprintf
(
stderr
,
"Out of memory setting new config filename
\n
"
);
fprintf
(
stderr
,
"Out of memory setting new config filename
\n
"
);
lxc_container_put
(
c
);
goto
out
;
exit
(
EXIT_FAILURE
);
}
}
}
}
if
(
!
c
->
lxc_conf
)
{
if
(
!
c
->
lxc_conf
)
{
fprintf
(
stderr
,
"Executing a container with no configuration file may crash the host
\n
"
);
fprintf
(
stderr
,
"Executing a container with no configuration file may crash the host
\n
"
);
lxc_container_put
(
c
);
goto
out
;
exit
(
EXIT_FAILURE
);
}
}
if
(
my_args
.
argc
==
0
)
{
if
(
my_args
.
argc
==
0
)
{
if
(
!
set_argv
(
c
,
&
my_args
))
{
if
(
!
set_argv
(
c
,
&
my_args
))
{
fprintf
(
stderr
,
"missing command to execute!
\n
"
);
fprintf
(
stderr
,
"missing command to execute!
\n
"
);
lxc_container_put
(
c
);
goto
out
;
exit
(
EXIT_FAILURE
);
}
}
}
}
bret
=
lxc_config_define_load
(
&
defines
,
c
);
bret
=
lxc_config_define_load
(
&
defines
,
c
);
if
(
!
bret
)
{
if
(
!
bret
)
lxc_container_put
(
c
);
goto
out
;
exit
(
EXIT_FAILURE
);
}
if
(
my_args
.
uid
)
{
if
(
my_args
.
uid
)
{
char
buf
[
256
];
char
buf
[
256
];
ret
=
snprintf
(
buf
,
256
,
"%d"
,
my_args
.
uid
);
ret
=
snprintf
(
buf
,
256
,
"%d"
,
my_args
.
uid
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
256
)
{
if
(
ret
<
0
||
(
size_t
)
ret
>=
256
)
lxc_container_put
(
c
);
goto
out
;
exit
(
EXIT_FAILURE
);
}
bret
=
c
->
set_config_item
(
c
,
"lxc.init.uid"
,
buf
);
bret
=
c
->
set_config_item
(
c
,
"lxc.init.uid"
,
buf
);
if
(
!
bret
)
{
if
(
!
bret
)
lxc_container_put
(
c
);
goto
out
;
exit
(
EXIT_FAILURE
);
}
}
}
if
(
my_args
.
gid
)
{
if
(
my_args
.
gid
)
{
char
buf
[
256
];
char
buf
[
256
];
ret
=
snprintf
(
buf
,
256
,
"%d"
,
my_args
.
gid
);
ret
=
snprintf
(
buf
,
256
,
"%d"
,
my_args
.
gid
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
256
)
{
if
(
ret
<
0
||
(
size_t
)
ret
>=
256
)
lxc_container_put
(
c
);
goto
out
;
exit
(
EXIT_FAILURE
);
}
bret
=
c
->
set_config_item
(
c
,
"lxc.init.gid"
,
buf
);
bret
=
c
->
set_config_item
(
c
,
"lxc.init.gid"
,
buf
);
if
(
!
bret
)
{
if
(
!
bret
)
lxc_container_put
(
c
);
goto
out
;
exit
(
EXIT_FAILURE
);
}
}
}
if
(
!
lxc_setup_shared_ns
(
&
my_args
,
c
))
{
if
(
!
lxc_setup_shared_ns
(
&
my_args
,
c
))
lxc_container_put
(
c
);
goto
out
;
exit
(
EXIT_FAILURE
);
}
c
->
daemonize
=
my_args
.
daemonize
==
1
;
c
->
daemonize
=
my_args
.
daemonize
==
1
;
bret
=
c
->
start
(
c
,
1
,
my_args
.
argv
);
bret
=
c
->
start
(
c
,
1
,
my_args
.
argv
);
lxc_container_put
(
c
);
if
(
!
bret
)
{
if
(
!
bret
)
{
fprintf
(
stderr
,
"Failed run an application inside container
\n
"
);
fprintf
(
stderr
,
"Failed run an application inside container
\n
"
);
exit
(
EXIT_FAILURE
)
;
goto
out
;
}
}
if
(
c
->
daemonize
)
if
(
c
->
daemonize
)
{
e
xit
(
EXIT_SUCCESS
)
;
e
rr
=
EXIT_SUCCESS
;
else
{
}
else
{
if
(
WIFEXITED
(
c
->
error_num
))
{
if
(
WIFEXITED
(
c
->
error_num
))
{
e
xit
(
WEXITSTATUS
(
c
->
error_num
)
);
e
rr
=
WEXITSTATUS
(
c
->
error_num
);
}
else
{
}
else
{
/* Try to die with the same signal the task did. */
/* Try to die with the same signal the task did. */
kill
(
0
,
WTERMSIG
(
c
->
error_num
));
kill
(
0
,
WTERMSIG
(
c
->
error_num
));
exit
(
EXIT_FAILURE
);
}
}
}
}
out:
lxc_container_put
(
c
);
exit
(
err
);
}
}
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