Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix host component handling in file:// URLs #2342

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions libpkg/fetch_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,25 @@ file_open(struct pkg_repo *repo, struct fetch_item *fi)
return (EPKG_FATAL);
}
u+=2;
/* if we don't have a '/' it means we have a host we should ignore */
/* if we don't have a '/' it means we have a host FQDN component, otherwise just proceed */
/* we can fetch local files only, so we accept the localhost FQDN */
/* TODO: consider accepting gethostname/getdomainname and combinations of these. */
/* TODO: delegate to curl to fetch any URL, btw. curl bails on this as well. */
if (*u != '/') {
u = strchr(u+1, '/');
if (u == NULL) {
pkg_emit_error("Invalid url: %s'\n', "
"file://<absolutepath> expected", fi->url);
char fqdn[256]="";
char *path = strchr(u+1, '/');
if (path == NULL) {
pkg_emit_error("Invalid url: '%s',\n"
"file:///<path> or file://localhost/<path> expected.", fi->url);
return (EPKG_FATAL);
}
strncat(fqdn, u, MIN(255, path-u));
bapt marked this conversation as resolved.
Show resolved Hide resolved
if (0 != strncmp("localhost", fqdn, sizeof(fqdn))) {
pkg_emit_error("Invalid url: '%s'\n"
"file:///<path> or file://localhost/<path> expected.", fi->url);
return (EPKG_FATAL);
}
u = path;
}
if (stat(u, &st) == -1) {
if (!repo->silent)
Expand Down
42 changes: 39 additions & 3 deletions tests/frontend/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ EOF

atf_check \
-o match:"Unable to update repository test" \
-e match:"pkg: file://empty//packagesite.pkg: No such file or directory" \
-e match:"Invalid url: 'file://empty//meta.conf'" \
-s exit:1 \
pkg -R repos update
}
Expand All @@ -28,6 +28,10 @@ file_url_body() {
touch meta.conf
here=$(pwd)


#
# test file:/empty/, which is invalid
#
cat > repos/test.conf << EOF
test: {
url: "file:/empty/",
Expand All @@ -40,18 +44,24 @@ EOF
-s exit:1 \
pkg -R repos update

#
# test file://here, which is invalid
#
cat > repos/test.conf << EOF
test: {
url: "file://here",
}
EOF
atf_check \
-o match:"Unable to update repository test" \
-e match:"meta.*No such file or directory" \
-e match:"Invalid url: 'file://here/meta.conf'" \
-s exit:1 \
pkg -R repos update


#
# test file://here//path, which is invalid
#
cat > repos/test.conf << EOF
test: {
url: "file://here/${here}",
Expand All @@ -63,6 +73,9 @@ EOF
-s exit:1 \
pkg -R repos update

#
# test file:////path, which is valid
#
cat > repos/test.conf << EOF
test: {
url: "file:///${here}",
Expand All @@ -75,6 +88,9 @@ EOF
-s exit:1 \
pkg -R repos update

#
# test file:///path, which is valid
#
cat > repos/test.conf << EOF
test: {
url: "file://${here}",
Expand All @@ -87,6 +103,9 @@ EOF
-s exit:1 \
pkg -R repos update

#
# test file://path, which is invalid
#
cat > repos/test.conf << EOF
test: {
url: "file:/${here}",
Expand All @@ -95,7 +114,24 @@ EOF

atf_check \
-o match:"Unable to update repository test" \
-e match:"meta.*No such file or directory" \
-e match:"Invalid url: 'file:/${here}/meta.conf'" \
-s exit:1 \
pkg -R repos update


#
# test file://localhost/path, which is a valid
#
cat > repos/test.conf << EOF
test: {
url: "file://localhost${here}",
}
EOF

atf_check \
-o match:"Unable to update repository test" \
-e not-match:"meta.*No such file or directory" \
-s exit:1 \
pkg -R repos update

}
Loading