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
4581c22a
Commit
4581c22a
authored
Jan 22, 2011
by
nulltoken
Committed by
Vicent Marti
Jan 29, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimized git_prettify_dir_path() parsing.
parent
9dd34b1e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
21 deletions
+18
-21
src/fileops.c
+18
-21
No files found.
src/fileops.c
View file @
4581c22a
...
...
@@ -393,10 +393,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
,
*
end
;
int
len
=
0
,
segment_len
,
only_dots
;
char
*
current
;
const
char
*
buffer_out_start
,
*
buffer_end
;
int
only_dots
;
buffer_out_start
=
buffer_out
;
current
=
(
char
*
)
path
;
...
...
@@ -409,48 +408,46 @@ int git_prettify_dir_path(char *buffer_out, const char *path)
continue
;
}
end
=
current
;
only_dots
=
1
;
segment_len
=
0
;
/*
Seek end of path segmen
t */
while
(
end
<
buffer_end
&&
*
end
!=
'/'
)
/*
Copy path segment to the outpu
t */
while
(
current
<
buffer_end
&&
*
current
!=
'/'
)
{
only_dots
&=
(
*
end
==
'.'
);
end
++
;
only_dots
&=
(
*
current
==
'.'
);
*
buffer_out
++
=
*
current
++
;
segment_len
++
;
len
++
;
}
/* Skip current directory */
if
(
only_dots
&&
end
==
current
+
1
)
if
(
only_dots
&&
segment_len
==
1
)
{
current
+=
2
;
current
++
;
buffer_out
-=
segment_len
;
len
-=
segment_len
;
continue
;
}
/* Handle the double-dot upward directory navigation */
if
(
only_dots
&&
end
==
current
+
2
)
if
(
only_dots
&&
segment_len
==
2
)
{
current
++
;
buffer_out
-=
segment_len
;
*
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
;
}
/* Guard against potential multiple dot path traversal (cf http://cwe.mitre.org/data/definitions/33.html) */
if
(
only_dots
&&
end
>
current
)
if
(
only_dots
&&
segment_len
>
0
)
return
GIT_ERROR
;
/* Copy to output the path segment */
while
(
current
<
end
)
{
*
buffer_out
++
=
*
current
++
;
len
++
;
}
*
buffer_out
++
=
'/'
;
len
++
;
}
...
...
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