Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
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
lvzhengyang
git2
Commits
dd748dbe
Commit
dd748dbe
authored
Nov 01, 2021
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fs_path: make empty component validation optional
parent
bef02d3e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
15 deletions
+38
-15
src/fs_path.c
+4
-1
src/fs_path.h
+4
-1
tests/path/core.c
+30
-13
No files found.
src/fs_path.c
View file @
dd748dbe
...
...
@@ -1599,7 +1599,7 @@ static bool validate_component(
unsigned
int
flags
)
{
if
(
len
==
0
)
return
false
;
return
!
(
flags
&
GIT_FS_PATH_REJECT_EMPTY_COMPONENT
)
;
if
((
flags
&
GIT_FS_PATH_REJECT_TRAVERSAL
)
&&
len
==
1
&&
component
[
0
]
==
'.'
)
...
...
@@ -1644,6 +1644,9 @@ bool git_fs_path_is_valid_str_ext(
const
char
*
start
,
*
c
;
size_t
len
=
0
;
if
(
!
flags
)
return
true
;
for
(
start
=
c
=
path
->
ptr
;
*
c
&&
len
<
path
->
size
;
c
++
,
len
++
)
{
if
(
!
validate_char
(
*
c
,
flags
))
return
false
;
...
...
src/fs_path.h
View file @
dd748dbe
...
...
@@ -591,7 +591,8 @@ extern bool git_fs_path_is_local_file_url(const char *file_url);
extern
int
git_fs_path_from_url_or_path
(
git_str
*
local_path_out
,
const
char
*
url_or_path
);
/* Flags to determine path validity in `git_fs_path_isvalid` */
#define GIT_FS_PATH_REJECT_TRAVERSAL (1 << 0)
#define GIT_FS_PATH_REJECT_EMPTY_COMPONENT (1 << 0)
#define GIT_FS_PATH_REJECT_TRAVERSAL (1 << 1)
#define GIT_FS_PATH_REJECT_SLASH (1 << 2)
#define GIT_FS_PATH_REJECT_BACKSLASH (1 << 3)
#define GIT_FS_PATH_REJECT_TRAILING_DOT (1 << 4)
...
...
@@ -608,6 +609,7 @@ extern int git_fs_path_from_url_or_path(git_str *local_path_out, const char *url
*/
#ifdef GIT_WIN32
# define GIT_FS_PATH_REJECT_FILESYSTEM_DEFAULTS \
GIT_FS_PATH_REJECT_EMPTY_COMPONENT | \
GIT_FS_PATH_REJECT_TRAVERSAL | \
GIT_FS_PATH_REJECT_BACKSLASH | \
GIT_FS_PATH_REJECT_TRAILING_DOT | \
...
...
@@ -617,6 +619,7 @@ extern int git_fs_path_from_url_or_path(git_str *local_path_out, const char *url
GIT_FS_PATH_REJECT_NT_CHARS
#else
# define GIT_FS_PATH_REJECT_FILESYSTEM_DEFAULTS \
GIT_FS_PATH_REJECT_EMPTY_COMPONENT | \
GIT_FS_PATH_REJECT_TRAVERSAL
#endif
...
...
tests/path/core.c
View file @
dd748dbe
...
...
@@ -68,41 +68,58 @@ void test_path_core__isvalid_standard(void)
void
test_path_core__isvalid_standard_str
(
void
)
{
git_str
str
=
GIT_STR_INIT_CONST
(
"foo/bar//zap"
,
0
);
unsigned
int
flags
=
GIT_FS_PATH_REJECT_EMPTY_COMPONENT
;
str
.
size
=
0
;
cl_assert_equal_b
(
false
,
git_fs_path_is_valid_str
(
&
str
,
0
));
cl_assert_equal_b
(
false
,
git_fs_path_is_valid_str
(
&
str
,
flags
));
str
.
size
=
3
;
cl_assert_equal_b
(
true
,
git_fs_path_is_valid_str
(
&
str
,
0
));
cl_assert_equal_b
(
true
,
git_fs_path_is_valid_str
(
&
str
,
flags
));
str
.
size
=
4
;
cl_assert_equal_b
(
false
,
git_fs_path_is_valid_str
(
&
str
,
0
));
cl_assert_equal_b
(
false
,
git_fs_path_is_valid_str
(
&
str
,
flags
));
str
.
size
=
5
;
cl_assert_equal_b
(
true
,
git_fs_path_is_valid_str
(
&
str
,
0
));
cl_assert_equal_b
(
true
,
git_fs_path_is_valid_str
(
&
str
,
flags
));
str
.
size
=
7
;
cl_assert_equal_b
(
true
,
git_fs_path_is_valid_str
(
&
str
,
0
));
cl_assert_equal_b
(
true
,
git_fs_path_is_valid_str
(
&
str
,
flags
));
str
.
size
=
8
;
cl_assert_equal_b
(
false
,
git_fs_path_is_valid_str
(
&
str
,
0
));
cl_assert_equal_b
(
false
,
git_fs_path_is_valid_str
(
&
str
,
flags
));
str
.
size
=
strlen
(
str
.
ptr
);
cl_assert_equal_b
(
false
,
git_fs_path_is_valid_str
(
&
str
,
0
));
cl_assert_equal_b
(
false
,
git_fs_path_is_valid_str
(
&
str
,
flags
));
}
void
test_path_core__isvalid_empty_dir_component
(
void
)
{
cl_assert_equal_b
(
false
,
git_fs_path_is_valid
(
"foo//bar"
,
0
));
unsigned
int
flags
=
GIT_FS_PATH_REJECT_EMPTY_COMPONENT
;
/* empty component */
cl_assert_equal_b
(
true
,
git_fs_path_is_valid
(
"foo//bar"
,
0
));
/* leading slash */
cl_assert_equal_b
(
true
,
git_fs_path_is_valid
(
"/"
,
0
));
cl_assert_equal_b
(
true
,
git_fs_path_is_valid
(
"/foo"
,
0
));
cl_assert_equal_b
(
true
,
git_fs_path_is_valid
(
"/foo/bar"
,
0
));
/* trailing slash */
cl_assert_equal_b
(
true
,
git_fs_path_is_valid
(
"foo/"
,
0
));
cl_assert_equal_b
(
true
,
git_fs_path_is_valid
(
"foo/bar/"
,
0
));
/* empty component */
cl_assert_equal_b
(
false
,
git_fs_path_is_valid
(
"foo//bar"
,
flags
));
/* leading slash */
cl_assert_equal_b
(
false
,
git_fs_path_is_valid
(
"/"
,
0
));
cl_assert_equal_b
(
false
,
git_fs_path_is_valid
(
"/foo"
,
0
));
cl_assert_equal_b
(
false
,
git_fs_path_is_valid
(
"/foo/bar"
,
0
));
cl_assert_equal_b
(
false
,
git_fs_path_is_valid
(
"/"
,
flags
));
cl_assert_equal_b
(
false
,
git_fs_path_is_valid
(
"/foo"
,
flags
));
cl_assert_equal_b
(
false
,
git_fs_path_is_valid
(
"/foo/bar"
,
flags
));
/* trailing slash */
cl_assert_equal_b
(
false
,
git_fs_path_is_valid
(
"foo/"
,
0
));
cl_assert_equal_b
(
false
,
git_fs_path_is_valid
(
"foo/bar/"
,
0
));
cl_assert_equal_b
(
false
,
git_fs_path_is_valid
(
"foo/"
,
flags
));
cl_assert_equal_b
(
false
,
git_fs_path_is_valid
(
"foo/bar/"
,
flags
));
}
void
test_path_core__isvalid_dot_and_dotdot
(
void
)
...
...
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