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
28e54be1
Unverified
Commit
28e54be1
authored
Mar 30, 2021
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
string_utils: switch to path_simplify()
Link:
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=32689
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
ec6de2c3
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
56 additions
and
47 deletions
+56
-47
confile_utils.c
src/lxc/confile_utils.c
+5
-5
criu.c
src/lxc/criu.c
+1
-1
overlay.c
src/lxc/storage/overlay.c
+2
-2
string_utils.c
src/lxc/string_utils.c
+40
-33
string_utils.h
src/lxc/string_utils.h
+2
-0
lxc-test-utils.c
src/tests/lxc-test-utils.c
+6
-6
No files found.
src/lxc/confile_utils.c
View file @
28e54be1
...
@@ -667,13 +667,13 @@ int set_config_string_item_max(char **conf_item, const char *value, size_t max)
...
@@ -667,13 +667,13 @@ int set_config_string_item_max(char **conf_item, const char *value, size_t max)
int
set_config_path_item
(
char
**
conf_item
,
const
char
*
value
)
int
set_config_path_item
(
char
**
conf_item
,
const
char
*
value
)
{
{
__do_free
char
*
normalized
=
NULL
;
__do_free
char
*
valdup
=
NULL
;
normalized
=
lxc_deslash
ify
(
value
);
valdup
=
path_simpl
ify
(
value
);
if
(
!
normalized
)
if
(
!
valdup
)
return
syserror_set
(
-
ENOMEM
,
"Failed to normalize path config item"
)
;
return
-
ENOMEM
;
return
set_config_string_item_max
(
conf_item
,
normalized
,
PATH_MAX
);
return
set_config_string_item_max
(
conf_item
,
valdup
,
PATH_MAX
);
}
}
int
set_config_bool_item
(
bool
*
conf_item
,
const
char
*
value
,
bool
empty_conf_action
)
int
set_config_bool_item
(
bool
*
conf_item
,
const
char
*
value
,
bool
empty_conf_action
)
...
...
src/lxc/criu.c
View file @
28e54be1
...
@@ -319,7 +319,7 @@ static int exec_criu(struct cgroup_ops *cgroup_ops, struct lxc_conf *conf,
...
@@ -319,7 +319,7 @@ static int exec_criu(struct cgroup_ops *cgroup_ops, struct lxc_conf *conf,
return
log_error_errno
(
-
ENOMEM
,
ENOMEM
,
"Failed to duplicate limit cgroup path"
);
return
log_error_errno
(
-
ENOMEM
,
ENOMEM
,
"Failed to duplicate limit cgroup path"
);
}
}
tmp
=
lxc_deslash
ify
(
cgroup_base_path
);
tmp
=
path_simpl
ify
(
cgroup_base_path
);
if
(
!
tmp
)
if
(
!
tmp
)
return
log_error_errno
(
-
ENOMEM
,
ENOMEM
,
"Failed to remove extraneous slashes from
\"
%s
\"
"
,
tmp
);
return
log_error_errno
(
-
ENOMEM
,
ENOMEM
,
"Failed to remove extraneous slashes from
\"
%s
\"
"
,
tmp
);
free_move_ptr
(
cgroup_base_path
,
tmp
);
free_move_ptr
(
cgroup_base_path
,
tmp
);
...
...
src/lxc/storage/overlay.c
View file @
28e54be1
...
@@ -192,11 +192,11 @@ int ovl_clonepaths(struct lxc_storage *orig, struct lxc_storage *new, const char
...
@@ -192,11 +192,11 @@ int ovl_clonepaths(struct lxc_storage *orig, struct lxc_storage *new, const char
* don't need to record a dependency. If we would restore would
* don't need to record a dependency. If we would restore would
* also fail.
* also fail.
*/
*/
clean_old_path
=
lxc_deslash
ify
(
oldpath
);
clean_old_path
=
path_simpl
ify
(
oldpath
);
if
(
!
clean_old_path
)
if
(
!
clean_old_path
)
return
log_error_errno
(
-
ENOMEM
,
ENOMEM
,
"Failed to create clean path for
\"
%s
\"
"
,
oldpath
);
return
log_error_errno
(
-
ENOMEM
,
ENOMEM
,
"Failed to create clean path for
\"
%s
\"
"
,
oldpath
);
clean_new_path
=
lxc_deslash
ify
(
lxcpath
);
clean_new_path
=
path_simpl
ify
(
lxcpath
);
if
(
!
clean_new_path
)
if
(
!
clean_new_path
)
return
log_error_errno
(
-
ENOMEM
,
ENOMEM
,
"Failed to create clean path for
\"
%s
\"
"
,
lxcpath
);
return
log_error_errno
(
-
ENOMEM
,
ENOMEM
,
"Failed to create clean path for
\"
%s
\"
"
,
lxcpath
);
...
...
src/lxc/string_utils.c
View file @
28e54be1
...
@@ -195,7 +195,6 @@ char *lxc_string_join(const char *sep, const char **parts, bool use_as_prefix)
...
@@ -195,7 +195,6 @@ char *lxc_string_join(const char *sep, const char **parts, bool use_as_prefix)
char
**
lxc_normalize_path
(
const
char
*
path
)
char
**
lxc_normalize_path
(
const
char
*
path
)
{
{
char
**
components
;
char
**
components
;
char
**
p
;
size_t
components_len
=
0
;
size_t
components_len
=
0
;
size_t
pos
=
0
;
size_t
pos
=
0
;
...
@@ -203,9 +202,6 @@ char **lxc_normalize_path(const char *path)
...
@@ -203,9 +202,6 @@ char **lxc_normalize_path(const char *path)
if
(
!
components
)
if
(
!
components
)
return
NULL
;
return
NULL
;
for
(
p
=
components
;
*
p
;
p
++
)
components_len
++
;
/* resolve '.' and '..' */
/* resolve '.' and '..' */
for
(
pos
=
0
;
pos
<
components_len
;)
{
for
(
pos
=
0
;
pos
<
components_len
;)
{
if
(
strequal
(
components
[
pos
],
"."
)
||
if
(
strequal
(
components
[
pos
],
"."
)
||
...
@@ -231,47 +227,58 @@ char **lxc_normalize_path(const char *path)
...
@@ -231,47 +227,58 @@ char **lxc_normalize_path(const char *path)
return
components
;
return
components
;
}
}
char
*
lxc_deslashify
(
const
char
*
path
)
/* taken from systemd */
char
*
path_simplify
(
const
char
*
path
)
{
{
char
*
dup
,
*
p
;
__do_free
char
*
path_new
=
NULL
;
char
*
*
parts
=
NULL
;
char
*
f
,
*
t
;
size_t
n
,
len
;
bool
slash
=
false
,
ignore_slash
=
false
,
absolute
;
dup
=
strdup
(
path
);
path_new
=
strdup
(
path
);
if
(
!
dup
)
if
(
!
path_new
)
return
NULL
;
return
NULL
;
parts
=
lxc_normalize_path
(
dup
);
if
(
is_empty_string
(
path_new
))
if
(
!
parts
)
{
return
move_ptr
(
path_new
);
free
(
dup
);
return
NULL
;
absolute
=
abspath
(
path_new
);
f
=
path_new
;
if
(
*
f
==
'.'
&&
IN_SET
(
f
[
1
],
0
,
'/'
))
{
ignore_slash
=
true
;
f
++
;
}
}
/* We'll end up here if path == "///" or path == "". */
for
(
t
=
path_new
;
*
f
;
f
++
)
{
if
(
!*
parts
)
{
len
=
strlen
(
dup
);
if
(
!
len
)
{
lxc_free_array
((
void
**
)
parts
,
free
);
return
dup
;
}
n
=
strcspn
(
dup
,
"/"
);
if
(
*
f
==
'/'
)
{
if
(
n
==
len
)
{
slash
=
true
;
free
(
dup
)
;
continue
;
lxc_free_array
((
void
**
)
parts
,
free
);
}
p
=
strdup
(
"/"
);
if
(
slash
)
{
if
(
!
p
)
if
(
*
f
==
'.'
&&
IN_SET
(
f
[
1
],
0
,
'/'
)
)
return
NULL
;
continue
;
return
p
;
slash
=
false
;
if
(
ignore_slash
)
ignore_slash
=
false
;
else
*
(
t
++
)
=
'/'
;
}
}
*
(
t
++
)
=
*
f
;
}
if
(
t
==
path_new
)
{
if
(
absolute
)
*
(
t
++
)
=
'/'
;
else
*
(
t
++
)
=
'.'
;
}
}
p
=
lxc_string_join
(
"/"
,
(
const
char
**
)
parts
,
*
dup
==
'/'
);
*
t
=
0
;
free
(
dup
);
return
move_ptr
(
path_new
);
lxc_free_array
((
void
**
)
parts
,
free
);
return
p
;
}
}
char
*
lxc_append_paths
(
const
char
*
first
,
const
char
*
second
)
char
*
lxc_append_paths
(
const
char
*
first
,
const
char
*
second
)
...
...
src/lxc/string_utils.h
View file @
28e54be1
...
@@ -196,4 +196,6 @@ static inline const char *fdstr(int fd)
...
@@ -196,4 +196,6 @@ static inline const char *fdstr(int fd)
(__iterator = __it); \
(__iterator = __it); \
__iterator = __it = strtok_r(NULL, __separators, &__p))
__iterator = __it = strtok_r(NULL, __separators, &__p))
__hidden
extern
char
*
path_simplify
(
const
char
*
path
);
#endif
/* __LXC_STRING_UTILS_H */
#endif
/* __LXC_STRING_UTILS_H */
src/tests/lxc-test-utils.c
View file @
28e54be1
...
@@ -43,12 +43,12 @@
...
@@ -43,12 +43,12 @@
#include "macro.h"
#include "macro.h"
#include "utils.h"
#include "utils.h"
void
test_
lxc_deslash
ify
(
void
)
void
test_
path_simpl
ify
(
void
)
{
{
char
*
s
=
"/A///B//C/D/E/"
;
char
*
s
=
"/A///B//C/D/E/"
;
char
*
t
;
char
*
t
;
t
=
lxc_deslash
ify
(
s
);
t
=
path_simpl
ify
(
s
);
if
(
!
t
)
if
(
!
t
)
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
...
@@ -57,7 +57,7 @@ void test_lxc_deslashify(void)
...
@@ -57,7 +57,7 @@ void test_lxc_deslashify(void)
s
=
"/A"
;
s
=
"/A"
;
t
=
lxc_deslash
ify
(
s
);
t
=
path_simpl
ify
(
s
);
if
(
!
t
)
if
(
!
t
)
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
...
@@ -65,7 +65,7 @@ void test_lxc_deslashify(void)
...
@@ -65,7 +65,7 @@ void test_lxc_deslashify(void)
free
(
t
);
free
(
t
);
s
=
""
;
s
=
""
;
t
=
lxc_deslash
ify
(
s
);
t
=
path_simpl
ify
(
s
);
if
(
!
t
)
if
(
!
t
)
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
...
@@ -74,7 +74,7 @@ void test_lxc_deslashify(void)
...
@@ -74,7 +74,7 @@ void test_lxc_deslashify(void)
s
=
"//"
;
s
=
"//"
;
t
=
lxc_deslash
ify
(
s
);
t
=
path_simpl
ify
(
s
);
if
(
!
t
)
if
(
!
t
)
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
...
@@ -598,7 +598,7 @@ int main(int argc, char *argv[])
...
@@ -598,7 +598,7 @@ int main(int argc, char *argv[])
{
{
test_lxc_string_replace
();
test_lxc_string_replace
();
test_lxc_string_in_array
();
test_lxc_string_in_array
();
test_
lxc_deslash
ify
();
test_
path_simpl
ify
();
test_detect_ramfs_rootfs
();
test_detect_ramfs_rootfs
();
test_lxc_safe_uint
();
test_lxc_safe_uint
();
test_lxc_safe_int
();
test_lxc_safe_int
();
...
...
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