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
cb2ce6d0
Unverified
Commit
cb2ce6d0
authored
Oct 07, 2018
by
Stéphane Graber
Committed by
GitHub
Oct 07, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2674 from brauner/2018-10-07/protect_errno
parse: tweak config parsing
parents
8f355cad
872c1f04
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
18 deletions
+24
-18
confile.c
src/lxc/confile.c
+0
-4
parse.c
src/lxc/parse.c
+24
-14
No files found.
src/lxc/confile.c
View file @
cb2ce6d0
...
...
@@ -2499,10 +2499,6 @@ int lxc_config_read(const char *file, struct lxc_conf *conf, bool from_include)
c
.
conf
=
conf
;
c
.
from_include
=
from_include
;
ret
=
access
(
file
,
R_OK
);
if
(
ret
<
0
)
return
-
1
;
/* Catch only the top level config file name in the structure. */
if
(
!
conf
->
rcfile
)
conf
->
rcfile
=
strdup
(
file
);
...
...
src/lxc/parse.c
View file @
cb2ce6d0
...
...
@@ -65,34 +65,35 @@ int lxc_strmunmap(void *addr, size_t length)
return
munmap
(
addr
,
length
+
1
);
}
int
lxc_file_for_each_line_mmap
(
const
char
*
file
,
lxc_file_cb
callback
,
void
*
data
)
int
lxc_file_for_each_line_mmap
(
const
char
*
file
,
lxc_file_cb
callback
,
void
*
data
)
{
int
fd
;
int
fd
,
saved_errno
;
char
*
buf
,
*
line
;
struct
stat
st
;
int
ret
=
0
;
fd
=
open
(
file
,
O_RDONLY
|
O_CLOEXEC
);
if
(
fd
<
0
)
if
(
fd
<
0
)
{
SYSERROR
(
"Failed to open config file
\"
%s
\"
"
,
file
);
return
-
1
;
}
ret
=
fstat
(
fd
,
&
st
);
if
(
ret
<
0
)
{
close
(
fd
);
return
-
1
;
SYSERROR
(
"Failed to stat config file
\"
%s
\"
"
,
file
);
goto
on_error
;
}
if
(
st
.
st_size
==
0
)
{
close
(
fd
);
return
0
;
}
ret
=
0
;
if
(
st
.
st_size
==
0
)
goto
on_error
;
ret
=
-
1
;
buf
=
lxc_strmmap
(
NULL
,
st
.
st_size
,
PROT_READ
|
PROT_WRITE
,
MAP_PRIVATE
|
MAP_POPULATE
,
fd
,
0
);
if
(
buf
==
MAP_FAILED
)
{
close
(
fd
);
return
-
1
;
SYSERROR
(
"Failed to map config file
\"
%s
\"
"
,
file
);
goto
on_error
;
}
lxc_iterate_parts
(
line
,
buf
,
"
\n\0
"
)
{
...
...
@@ -102,13 +103,22 @@ int lxc_file_for_each_line_mmap(const char *file, lxc_file_cb callback,
* error.
*/
if
(
ret
<
0
)
ERROR
(
"Failed to parse config: %s"
,
line
);
ERROR
(
"Failed to parse config file
\"
%s
\"
at "
"line
\"
%s
\"
"
,
file
,
line
);
break
;
}
}
lxc_strmunmap
(
buf
,
st
.
st_size
);
on_error:
ret
=
lxc_strmunmap
(
buf
,
st
.
st_size
);
if
(
ret
<
0
)
SYSERROR
(
"Failed to unmap config file
\"
%s
\"
"
,
file
);
saved_errno
=
errno
;
close
(
fd
);
errno
=
saved_errno
;
return
ret
;
}
...
...
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