Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
HardenedBSD
pkg
Commits
727f1c94
Commit
727f1c94
authored
Mar 12, 2021
by
Baptiste Daroussin
Browse files
repo: skip dead symlinks and symlinks pointing inside the repo
parent
33729720
Changes
2
Hide whitespace changes
Inline
Side-by-side
libpkg/pkg_repo_create.c
View file @
727f1c94
/*-
* Copyright (c) 2011-201
9
Baptiste Daroussin <bapt@FreeBSD.org>
* Copyright (c) 2011-20
2
1 Baptiste Daroussin <bapt@FreeBSD.org>
* Copyright (c) 2011-2012 Julien Laffaye <jlaffaye@FreeBSD.org>
* Copyright (c) 2011-2012 Marin Atanasov Nikolov <dnaeon@gmail.com>
* Copyright (c) 2012-2013 Matthew Seaman <matthew@FreeBSD.org>
...
...
@@ -218,7 +218,14 @@ pkg_create_repo_read_fts(struct pkg_fts_item **items, FTS *fts,
char
*
ext
;
int
linklen
=
0
;
char
tmp_name
[
MAXPATHLEN
]
=
{
0
};
char
repo_path
[
MAXPATHLEN
];
size_t
repo_path_len
;
if
(
realpath
(
repopath
,
repo_path
)
==
NULL
)
{
pkg_emit_errno
(
"invalid repo path"
,
repopath
);
return
(
EPKG_FATAL
);
}
repo_path_len
=
strlen
(
repo_path
);
errno
=
0
;
while
((
fts_ent
=
fts_read
(
fts
))
!=
NULL
)
{
...
...
@@ -246,6 +253,14 @@ pkg_create_repo_read_fts(struct pkg_fts_item **items, FTS *fts,
}
/* Follow symlinks. */
if
(
fts_ent
->
fts_info
==
FTS_SL
)
{
/*
* Skip symlinks pointing inside the repo
* and dead symlinks
*/
if
(
realpath
(
fts_ent
->
fts_path
,
tmp_name
)
==
NULL
)
continue
;
if
(
strncmp
(
repo_path
,
tmp_name
,
repo_path_len
)
==
0
)
continue
;
/* Skip symlinks to hashed packages */
if
(
meta
->
hash
)
{
linklen
=
readlink
(
fts_ent
->
fts_path
,
...
...
tests/frontend/repo.sh
View file @
727f1c94
...
...
@@ -6,7 +6,8 @@ tests_init \
repo_v1
\
repo_v2
\
repo_multiversion
\
repo_multiformat
repo_multiformat
\
repo_symlinks
repo_v1_body
()
{
touch
plop
...
...
@@ -181,3 +182,34 @@ EOF
atf_check
-o
match:
"Installing plop-1
\.
1"
\
pkg
-C
./pkg.conf
install
-y
plop
}
repo_symlinks_body
()
{
atf_check
-s
exit
:0 sh
${
RESOURCEDIR
}
/test_subr.sh new_pkg
test test
1.0
"
${
TMPDIR
}
"
atf_check pkg create
--format
txz
-M
test.ucl
mkdir
repo
ln
-sf
../test-1.0.txz ./repo/meh-1.0.txz
atf_check
-o
ignore pkg repo repo
cat
>
pkg.conf
<<
EOF
PKG_DBDIR=
${
TMPDIR
}
REPOS_DIR=[]
repositories: {
local: { url : file://
${
TMPDIR
}
/repo }
}
EOF
atf_check
-o
ignore
\
pkg
-C
./pkg.conf update
atf_check
-o
inline:
"test
\n
"
\
pkg
-C
./pkg.conf rquery
-a
"%n"
rm
-rf
repo
mkdir
repo
cp
test-1.0.txz repo/
ln
-fs
test-1.0.txz ./repo/meh-1.0.txz
atf_check
-o
ignore pkg repo repo
atf_check
-o
ignore
\
pkg
-C
./pkg.conf update
-f
atf_check
-o
inline:
"test
\n
"
\
pkg
-C
./pkg.conf rquery
-a
"%n"
}
Shawn Webb
@shawn.webb
mentioned in commit
6b27228f
·
Aug 10, 2021
mentioned in commit
6b27228f
mentioned in commit 6b27228f40a00ffe50e806102c84cb059f0d0a75
Toggle commit list
Shawn Webb
@shawn.webb
mentioned in commit
e3c836b0
·
Aug 10, 2021
mentioned in commit
e3c836b0
mentioned in commit e3c836b08edd2044a7ba1a237193617e7d7b91be
Toggle commit list
Write
Preview
Supports
Markdown
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