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
ae7ffea9
Commit
ae7ffea9
authored
Jan 22, 2011
by
nulltoken
Committed by
Vicent Marti
Jan 29, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed a parsing issue in git_prettify_dir_path().
parent
b29e8f19
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
27 deletions
+48
-27
src/fileops.c
+39
-26
tests/t0005-path.c
+9
-1
No files found.
src/fileops.c
View file @
ae7ffea9
...
...
@@ -394,8 +394,9 @@ static int retrieve_previous_path_component_start(const char *path)
int
git_prettify_dir_path
(
char
*
buffer_out
,
const
char
*
path
)
{
int
len
=
0
;
char
*
current
;
char
*
current
,
*
end
;
const
char
*
buffer_out_start
,
*
buffer_end
;
int
only_dots
;
buffer_out_start
=
buffer_out
;
current
=
(
char
*
)
path
;
...
...
@@ -408,40 +409,52 @@ int git_prettify_dir_path(char *buffer_out, const char *path)
continue
;
}
/* Skip current directory */
if
(
*
current
==
'.'
)
{
current
++
;
/* Handle the double-dot upward directory navigation */
if
(
current
<
buffer_end
&&
*
current
==
'.'
)
{
current
++
;
/* Guard against potential multiple dot path traversal (cf http://cwe.mitre.org/data/definitions/33.html) */
if
(
*
current
==
'.'
)
return
GIT_ERROR
;
end
=
current
;
only_dots
=
1
;
/* Seek end of path segment */
while
(
end
<
buffer_end
&&
*
end
!=
'/'
)
{
only_dots
&=
(
*
end
==
'.'
);
end
++
;
}
*
buffer_out
=
'\0'
;
len
=
retrieve_previous_path_component_start
(
buffer_out_start
);
if
(
len
<
GIT_SUCCESS
)
return
GIT_ERROR
;
/* Skip current directory */
if
(
only_dots
&&
end
==
current
+
1
)
{
current
+=
2
;
continue
;
}
buffer_out
=
(
char
*
)
buffer_out_start
+
len
;
}
/* Handle the double-dot upward directory navigation */
if
(
only_dots
&&
end
==
current
+
2
)
{
*
buffer_out
=
'\0'
;
len
=
retrieve_previous_path_component_start
(
buffer_out_start
);
if
(
len
<
GIT_SUCCESS
)
return
GIT_ERROR
;
buffer_out
=
(
char
*
)
buffer_out_start
+
len
;
current
+=
3
;
continue
;
}
if
(
current
<
buffer_end
&&
*
current
==
'/'
)
current
++
;
/* Guard against potential multiple dot path traversal (cf http://cwe.mitre.org/data/definitions/33.html) */
if
(
only_dots
&&
end
>
current
)
return
GIT_ERROR
;
continue
;
/* Copy to output the path segment */
while
(
current
<
end
)
{
*
buffer_out
++
=
*
current
++
;
len
++
;
}
*
buffer_out
++
=
*
current
++
;
*
buffer_out
++
=
'/'
;
len
++
;
}
/* Add a trailing slash if required */
if
(
len
>
0
&&
buffer_out_start
[
len
-
1
]
!=
'/'
)
*
buffer_out
++
=
'/'
;
*
buffer_out
=
'\0'
;
return
GIT_SUCCESS
;
...
...
tests/t0005-path.c
View file @
ae7ffea9
...
...
@@ -20,6 +20,10 @@ static int ensure_normalized(const char *input_path, const char *expected_path)
}
BEGIN_TEST
(
path_prettifying
)
must_pass
(
ensure_normalized
(
"./testrepo.git"
,
"testrepo.git/"
));
must_pass
(
ensure_normalized
(
"./.git"
,
".git/"
));
must_pass
(
ensure_normalized
(
"./git."
,
"git./"
));
must_pass
(
ensure_normalized
(
"git./"
,
"git./"
));
must_pass
(
ensure_normalized
(
""
,
""
));
must_pass
(
ensure_normalized
(
"."
,
""
));
must_pass
(
ensure_normalized
(
"./"
,
""
));
...
...
@@ -53,7 +57,11 @@ BEGIN_TEST(path_prettifying)
must_fail
(
ensure_normalized
(
"d1/..."
,
NULL
));
must_fail
(
ensure_normalized
(
"d1/.../"
,
NULL
));
must_fail
(
ensure_normalized
(
"d1/.../d2"
,
NULL
));
must_pass
(
ensure_normalized
(
"/./testrepo.git"
,
"/testrepo.git/"
));
must_pass
(
ensure_normalized
(
"/./.git"
,
"/.git/"
));
must_pass
(
ensure_normalized
(
"/./git."
,
"/git./"
));
must_pass
(
ensure_normalized
(
"/git./"
,
"/git./"
));
must_pass
(
ensure_normalized
(
"/"
,
"/"
));
must_pass
(
ensure_normalized
(
"//"
,
"/"
));
must_pass
(
ensure_normalized
(
"///"
,
"/"
));
...
...
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