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
4b957c22
Commit
4b957c22
authored
Jul 17, 1998
by
Andrew Tridgell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added the --safe-links option to disallow symlinks outside the
destination tree
parent
d853783f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
5 deletions
+47
-5
rsync.yo
rsync.yo
+0
-5
util.c
util.c
+47
-0
No files found.
rsync.yo
View file @
4b957c22
...
...
@@ -315,11 +315,6 @@ option all symbolic links are skipped.
dit(bf(-L, --copy-links)) This tells rsync to treat symbolic links just
like ordinary files.
dit(bf(--safe-links)) This tells rsync to ignore any symbolic links
which point outside the destination tree. All absolute symlinks are
also ignored. Using this option in conjunction with --relative may
give unexpecetd results.
dit(bf(-H, --hard-links)) This tells rsync to recreate hard links on
the remote system to be the same as the local system. Without this
option hard links are treated like regular files.
...
...
util.c
View file @
4b957c22
...
...
@@ -710,3 +710,50 @@ void show_progress(OFF_T ofs, OFF_T size)
}
}
}
/* determine if a symlink points outside the current directory tree */
int
unsafe_symlink
(
char
*
dest
,
char
*
src
)
{
char
*
tok
;
int
depth
=
0
;
/* all absolute and null symlinks are unsafe */
if
(
!
dest
||
!
(
*
dest
)
||
(
*
dest
==
'/'
))
return
1
;
src
=
strdup
(
src
);
if
(
!
src
)
out_of_memory
(
"unsafe_symlink"
);
/* find out what our safety margin is */
for
(
tok
=
strtok
(
src
,
"/"
);
tok
;
tok
=
strtok
(
NULL
,
"/"
))
{
if
(
strcmp
(
tok
,
".."
)
==
0
)
{
depth
=
0
;
}
else
if
(
strcmp
(
tok
,
"."
)
==
0
)
{
/* nothing */
}
else
{
depth
++
;
}
}
free
(
src
);
/* drop by one to account for the filename portion */
depth
--
;
dest
=
strdup
(
dest
);
if
(
!
dest
)
out_of_memory
(
"unsafe_symlink"
);
for
(
tok
=
strtok
(
dest
,
"/"
);
tok
;
tok
=
strtok
(
NULL
,
"/"
))
{
if
(
strcmp
(
tok
,
".."
)
==
0
)
{
depth
--
;
}
else
if
(
strcmp
(
tok
,
"."
)
==
0
)
{
/* nothing */
}
else
{
depth
++
;
}
/* if at any point we go outside the current directory then
stop - it is unsafe */
if
(
depth
<
0
)
break
;
}
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