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
07f89c1e
Unverified
Commit
07f89c1e
authored
Jun 26, 2020
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
confile: handle overflow in lxc.time.offset.{boot,monotonic}
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
b2ff0ccc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
24 deletions
+46
-24
confile.c
src/lxc/confile.c
+32
-24
utils.c
src/lxc/utils.c
+12
-0
utils.h
src/lxc/utils.h
+2
-0
No files found.
src/lxc/confile.c
View file @
07f89c1e
...
@@ -2831,22 +2831,26 @@ static int set_config_time_offset_boot(const char *key, const char *value,
...
@@ -2831,22 +2831,26 @@ static int set_config_time_offset_boot(const char *key, const char *value,
if
(
ret
)
if
(
ret
)
return
ret
;
return
ret
;
/* TODO: Handle overflow. */
unit
=
lxc_trim_whitespace_in_place
(
buf
);
unit
=
lxc_trim_whitespace_in_place
(
buf
);
if
(
strcmp
(
unit
,
"h"
)
==
0
)
if
(
strcmp
(
unit
,
"h"
)
==
0
)
{
lxc_conf
->
timens
.
s_boot
=
offset
*
3600
;
if
(
!
multiply_overflow
(
offset
,
3600
,
&
lxc_conf
->
timens
.
s_boot
))
else
if
(
strcmp
(
unit
,
"m"
)
==
0
)
return
-
EOVERFLOW
;
lxc_conf
->
timens
.
s_boot
=
offset
*
60
;
}
else
if
(
strcmp
(
unit
,
"m"
)
==
0
)
{
else
if
(
strcmp
(
unit
,
"s"
)
==
0
)
if
(
!
multiply_overflow
(
offset
,
60
,
&
lxc_conf
->
timens
.
s_boot
))
return
-
EOVERFLOW
;
}
else
if
(
strcmp
(
unit
,
"s"
)
==
0
)
{
lxc_conf
->
timens
.
s_boot
=
offset
;
lxc_conf
->
timens
.
s_boot
=
offset
;
else
if
(
strcmp
(
unit
,
"ms"
)
==
0
)
}
else
if
(
strcmp
(
unit
,
"ms"
)
==
0
)
{
lxc_conf
->
timens
.
ns_boot
=
offset
*
1000000
;
if
(
!
multiply_overflow
(
offset
,
1000000
,
&
lxc_conf
->
timens
.
ns_boot
))
else
if
(
strcmp
(
unit
,
"us"
)
==
0
)
return
-
EOVERFLOW
;
lxc_conf
->
timens
.
ns_boot
=
offset
*
1000
;
}
else
if
(
strcmp
(
unit
,
"us"
)
==
0
)
{
else
if
(
strcmp
(
unit
,
"ns"
)
==
0
)
if
(
!
multiply_overflow
(
offset
,
1000
,
&
lxc_conf
->
timens
.
ns_boot
))
return
-
EOVERFLOW
;
}
else
if
(
strcmp
(
unit
,
"ns"
)
==
0
)
{
lxc_conf
->
timens
.
ns_boot
=
offset
;
lxc_conf
->
timens
.
ns_boot
=
offset
;
else
}
else
{
return
ret_errno
(
EINVAL
);
return
ret_errno
(
EINVAL
);
}
return
0
;
return
0
;
}
}
...
@@ -2866,22 +2870,26 @@ static int set_config_time_offset_monotonic(const char *key, const char *value,
...
@@ -2866,22 +2870,26 @@ static int set_config_time_offset_monotonic(const char *key, const char *value,
if
(
ret
)
if
(
ret
)
return
ret
;
return
ret
;
// TODO: Handle overflow.
unit
=
lxc_trim_whitespace_in_place
(
buf
);
unit
=
lxc_trim_whitespace_in_place
(
buf
);
if
(
strcmp
(
unit
,
"h"
)
==
0
)
if
(
strcmp
(
unit
,
"h"
)
==
0
)
{
lxc_conf
->
timens
.
s_monotonic
=
offset
*
3600
;
if
(
!
multiply_overflow
(
offset
,
3600
,
&
lxc_conf
->
timens
.
s_monotonic
))
else
if
(
strcmp
(
unit
,
"m"
)
==
0
)
return
-
EOVERFLOW
;
lxc_conf
->
timens
.
s_monotonic
=
offset
*
60
;
}
else
if
(
strcmp
(
unit
,
"m"
)
==
0
)
{
else
if
(
strcmp
(
unit
,
"s"
)
==
0
)
if
(
!
multiply_overflow
(
offset
,
60
,
&
lxc_conf
->
timens
.
s_monotonic
))
return
-
EOVERFLOW
;
}
else
if
(
strcmp
(
unit
,
"s"
)
==
0
)
{
lxc_conf
->
timens
.
s_monotonic
=
offset
;
lxc_conf
->
timens
.
s_monotonic
=
offset
;
else
if
(
strcmp
(
unit
,
"ms"
)
==
0
)
}
else
if
(
strcmp
(
unit
,
"ms"
)
==
0
)
{
lxc_conf
->
timens
.
ns_monotonic
=
offset
*
1000000
;
if
(
!
multiply_overflow
(
offset
,
1000000
,
&
lxc_conf
->
timens
.
ns_monotonic
))
else
if
(
strcmp
(
unit
,
"us"
)
==
0
)
return
-
EOVERFLOW
;
lxc_conf
->
timens
.
ns_monotonic
=
offset
*
1000
;
}
else
if
(
strcmp
(
unit
,
"us"
)
==
0
)
{
else
if
(
strcmp
(
unit
,
"ns"
)
==
0
)
if
(
!
multiply_overflow
(
offset
,
1000
,
&
lxc_conf
->
timens
.
ns_monotonic
))
return
-
EOVERFLOW
;
}
else
if
(
strcmp
(
unit
,
"ns"
)
==
0
)
{
lxc_conf
->
timens
.
ns_monotonic
=
offset
;
lxc_conf
->
timens
.
ns_monotonic
=
offset
;
else
}
else
{
return
ret_errno
(
EINVAL
);
return
ret_errno
(
EINVAL
);
}
return
0
;
return
0
;
}
}
...
...
src/lxc/utils.c
View file @
07f89c1e
...
@@ -1904,3 +1904,15 @@ int fix_stdio_permissions(uid_t uid)
...
@@ -1904,3 +1904,15 @@ int fix_stdio_permissions(uid_t uid)
return
fret
;
return
fret
;
}
}
bool
multiply_overflow
(
int64_t
base
,
uint64_t
mult
,
int64_t
*
res
)
{
if
(
base
>
0
&&
base
>
(
INT64_MAX
/
mult
))
return
false
;
if
(
base
<
0
&&
base
<
(
INT64_MIN
/
mult
))
return
false
;
*
res
=
base
*
mult
;
return
true
;
}
src/lxc/utils.h
View file @
07f89c1e
...
@@ -251,4 +251,6 @@ static inline bool gid_valid(gid_t gid)
...
@@ -251,4 +251,6 @@ static inline bool gid_valid(gid_t gid)
return
gid
!=
LXC_INVALID_GID
;
return
gid
!=
LXC_INVALID_GID
;
}
}
extern
bool
multiply_overflow
(
int64_t
base
,
uint64_t
mult
,
int64_t
*
res
);
#endif
/* __LXC_UTILS_H */
#endif
/* __LXC_UTILS_H */
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