Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
liblongpath-rsync
Project
Project
Details
Activity
Releases
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liblongpath
liblongpath-rsync
Commits
7afa3a4a
Commit
7afa3a4a
authored
Jan 19, 2003
by
Wayne Davison
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimized unsafe_symlink() to avoid malloc/free calls.
parent
c80b3d8c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
24 deletions
+17
-24
util.c
util.c
+17
-24
No files found.
util.c
View file @
7afa3a4a
...
...
@@ -793,49 +793,42 @@ int u_strcmp(const char *cs1, const char *cs2)
*
* @sa t_unsafe.c
**/
int
unsafe_symlink
(
const
char
*
dest
_path
,
const
char
*
src_path
)
int
unsafe_symlink
(
const
char
*
dest
,
const
char
*
src
)
{
c
har
*
tok
,
*
src
,
*
dest
;
c
onst
char
*
name
,
*
slash
;
int
depth
=
0
;
/* all absolute and null symlinks are unsafe */
if
(
!
dest_path
||
!*
dest_path
||
*
dest_path
==
'/'
)
return
1
;
src
=
strdup
(
src_path
);
if
(
!
src
)
out_of_memory
(
"unsafe_symlink"
);
if
(
!
dest
||
!*
dest
||
*
dest
==
'/'
)
return
1
;
/* find out what our safety margin is */
for
(
tok
=
strtok
(
src
,
"/"
);
tok
;
tok
=
strtok
(
NULL
,
"/"
)
)
{
if
(
str
cmp
(
tok
,
".."
)
==
0
)
{
for
(
name
=
src
;
(
slash
=
strchr
(
name
,
'/'
))
!=
0
;
name
=
slash
+
1
)
{
if
(
str
ncmp
(
name
,
"../"
,
3
)
==
0
)
{
depth
=
0
;
}
else
if
(
str
cmp
(
tok
,
"."
)
==
0
)
{
}
else
if
(
str
ncmp
(
name
,
"./"
,
2
)
==
0
)
{
/* nothing */
}
else
{
depth
++
;
}
}
free
(
src
);
/* drop by one to account for the filename portion */
depth
--
;
dest
=
strdup
(
dest_path
);
if
(
!
dest
)
out_of_memory
(
"unsafe_symlink"
);
if
(
strcmp
(
name
,
".."
)
==
0
)
depth
=
0
;
for
(
tok
=
strtok
(
dest
,
"/"
);
tok
;
tok
=
strtok
(
NULL
,
"/"
))
{
if
(
strcmp
(
tok
,
".."
)
==
0
)
{
depth
--
;
}
else
if
(
strcmp
(
tok
,
"."
)
==
0
)
{
for
(
name
=
dest
;
(
slash
=
strchr
(
name
,
'/'
))
!=
0
;
name
=
slash
+
1
)
{
if
(
strncmp
(
name
,
"../"
,
3
)
==
0
)
{
/* if at any point we go outside the current directory
then stop - it is unsafe */
if
(
--
depth
<
0
)
return
1
;
}
else
if
(
strncmp
(
name
,
"./"
,
2
)
==
0
)
{
/* nothing */
}
else
{
depth
++
;
}
/* if at any point we go outside the current directory then
stop - it is unsafe */
if
(
depth
<
0
)
break
;
}
if
(
strcmp
(
name
,
".."
)
==
0
)
depth
--
;
free
(
dest
);
return
(
depth
<
0
);
}
...
...
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