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
7be721c1
Commit
7be721c1
authored
Sep 26, 2016
by
Stéphane Graber
Committed by
GitHub
Sep 26, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1209 from brauner/2016-09-25/lxc_deslashify
2016 09 25/lxc deslashify
parents
5d1f62b4
1a514c15
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
10 deletions
+62
-10
criu.c
src/lxc/criu.c
+1
-1
utils.c
src/lxc/utils.c
+27
-8
utils.h
src/lxc/utils.h
+1
-1
lxc-test-utils.c
src/tests/lxc-test-utils.c
+33
-0
No files found.
src/lxc/criu.c
View file @
7be721c1
...
@@ -282,7 +282,7 @@ static void exec_criu(struct criu_opts *opts)
...
@@ -282,7 +282,7 @@ static void exec_criu(struct criu_opts *opts)
}
}
}
}
if
(
!
lxc_deslashify
(
path
))
{
if
(
!
lxc_deslashify
(
&
path
))
{
ERROR
(
"failed to deslashify %s"
,
path
);
ERROR
(
"failed to deslashify %s"
,
path
);
free
(
path
);
free
(
path
);
goto
err
;
goto
err
;
...
...
src/lxc/utils.c
View file @
7be721c1
...
@@ -716,21 +716,40 @@ char **lxc_normalize_path(const char *path)
...
@@ -716,21 +716,40 @@ char **lxc_normalize_path(const char *path)
return
components
;
return
components
;
}
}
bool
lxc_deslashify
(
char
*
path
)
bool
lxc_deslashify
(
char
*
*
path
)
{
{
char
**
parts
=
NULL
,
*
path2
;
char
*
p
;
char
**
parts
=
NULL
;
size_t
n
,
len
;
parts
=
lxc_normalize_path
(
path
);
parts
=
lxc_normalize_path
(
*
path
);
if
(
!
parts
)
if
(
!
parts
)
return
false
;
return
false
;
path2
=
lxc_string_join
(
"/"
,
(
const
char
**
)
parts
,
*
path
==
'/'
);
/* We'll end up here if path == "///" or path == "". */
lxc_free_array
((
void
**
)
parts
,
free
);
if
(
!*
parts
)
{
if
(
!
path2
)
len
=
strlen
(
*
path
);
if
(
!
len
)
return
true
;
n
=
strcspn
(
*
path
,
"/"
);
if
(
n
==
len
)
{
p
=
strdup
(
"/"
);
if
(
!
p
)
return
false
;
free
(
*
path
);
*
path
=
p
;
return
true
;
}
}
p
=
lxc_string_join
(
"/"
,
(
const
char
**
)
parts
,
**
path
==
'/'
);
lxc_free_array
((
void
**
)
parts
,
free
);
if
(
!
p
)
return
false
;
return
false
;
strncpy
(
path
,
path2
,
strlen
(
path
));
free
(
*
path
);
free
(
path2
);
*
path
=
p
;
return
true
;
return
true
;
}
}
...
...
src/lxc/utils.h
View file @
7be721c1
...
@@ -249,7 +249,7 @@ extern char *lxc_string_join(const char *sep, const char **parts, bool use_as_pr
...
@@ -249,7 +249,7 @@ extern char *lxc_string_join(const char *sep, const char **parts, bool use_as_pr
*/
*/
extern
char
**
lxc_normalize_path
(
const
char
*
path
);
extern
char
**
lxc_normalize_path
(
const
char
*
path
);
/* remove multiple slashes from the path, e.g. ///foo//bar -> /foo/bar */
/* remove multiple slashes from the path, e.g. ///foo//bar -> /foo/bar */
extern
bool
lxc_deslashify
(
char
*
path
);
extern
bool
lxc_deslashify
(
char
*
*
path
);
extern
char
*
lxc_append_paths
(
const
char
*
first
,
const
char
*
second
);
extern
char
*
lxc_append_paths
(
const
char
*
first
,
const
char
*
second
);
/* Note: the following two functions use strtok(), so they will never
/* Note: the following two functions use strtok(), so they will never
* consider an empty element, even if two delimiters are next to
* consider an empty element, even if two delimiters are next to
...
...
src/tests/lxc-test-utils.c
View file @
7be721c1
...
@@ -21,6 +21,7 @@
...
@@ -21,6 +21,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
...
@@ -28,6 +29,37 @@
...
@@ -28,6 +29,37 @@
#include "lxctest.h"
#include "lxctest.h"
#include "utils.h"
#include "utils.h"
void
test_lxc_deslashify
(
void
)
{
char
*
s
=
strdup
(
"/A///B//C/D/E/"
);
if
(
!
s
)
exit
(
EXIT_FAILURE
);
lxc_test_assert_abort
(
lxc_deslashify
(
&
s
));
lxc_test_assert_abort
(
strcmp
(
s
,
"/A/B/C/D/E"
)
==
0
);
free
(
s
);
s
=
strdup
(
"/A"
);
if
(
!
s
)
exit
(
EXIT_FAILURE
);
lxc_test_assert_abort
(
lxc_deslashify
(
&
s
));
lxc_test_assert_abort
(
strcmp
(
s
,
"/A"
)
==
0
);
free
(
s
);
s
=
strdup
(
""
);
if
(
!
s
)
exit
(
EXIT_FAILURE
);
lxc_test_assert_abort
(
lxc_deslashify
(
&
s
));
lxc_test_assert_abort
(
strcmp
(
s
,
""
)
==
0
);
free
(
s
);
s
=
strdup
(
"//"
);
if
(
!
s
)
exit
(
EXIT_FAILURE
);
lxc_test_assert_abort
(
lxc_deslashify
(
&
s
));
lxc_test_assert_abort
(
strcmp
(
s
,
"/"
)
==
0
);
free
(
s
);
}
void
test_lxc_string_replace
(
void
)
void
test_lxc_string_replace
(
void
)
{
{
char
*
s
;
char
*
s
;
...
@@ -84,6 +116,7 @@ int main(int argc, char *argv[])
...
@@ -84,6 +116,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_deslashify
();
exit
(
EXIT_SUCCESS
);
exit
(
EXIT_SUCCESS
);
}
}
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