git: 5b952262d3e2 - main - pkg-serve: do not leak whether a path exists
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 17 Nov 2026 11:56:50 UTC
The branch main has been updated by bapt:
URL: https://cgit.FreeBSD.org/src/commit/?id=5b952262d3e223c033849441320bb12796bc52e4
commit 5b952262d3e223c033849441320bb12796bc52e4
Author: Baptiste Daroussin <bapt@FreeBSD.org>
AuthorDate: 2026-11-17 11:52:17 +0000
Commit: Baptiste Daroussin <bapt@FreeBSD.org>
CommitDate: 2026-11-17 11:55:19 +0000
pkg-serve: do not leak whether a path exists
Report "ko: file not found" for non-regular files as well, so a
client cannot tell an existing path from a missing one.
---
libexec/pkg-serve/pkg-serve.c | 2 +-
libexec/pkg-serve/tests/pkg_serve_test.sh | 24 ++++++++++++++++++++----
2 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/libexec/pkg-serve/pkg-serve.c b/libexec/pkg-serve/pkg-serve.c
index cbe3c7689a93..b087f9971c3f 100644
--- a/libexec/pkg-serve/pkg-serve.c
+++ b/libexec/pkg-serve/pkg-serve.c
@@ -174,7 +174,7 @@ main(int argc, char *argv[])
if (!S_ISREG(st.st_mode)) {
close(ffd);
- printf("ko: not a file\n");
+ printf("ko: file not found\n");
fflush(stdout);
continue;
}
diff --git a/libexec/pkg-serve/tests/pkg_serve_test.sh b/libexec/pkg-serve/tests/pkg_serve_test.sh
index 60ab92e2114c..9015209fa6e7 100644
--- a/libexec/pkg-serve/tests/pkg_serve_test.sh
+++ b/libexec/pkg-serve/tests/pkg_serve_test.sh
@@ -112,8 +112,8 @@ get_directory_head()
get_directory_body()
{
mkdir -p repo/subdir
- check_output "ko: not a file" "get subdir 0\nquit\n" repo ||
- atf_fail "expected not a file"
+ check_output "ko: file not found" "get subdir 0\nquit\n" repo ||
+ atf_fail "expected file not found"
}
atf_test_case get_missing_age
@@ -163,14 +163,29 @@ get_fifo_body()
mkfifo repo/fifo
output=$(printf 'get fifo 0\nquit\n' | timeout 10 "${PKG_SERVE}" repo)
case "$output" in
- *"ko: not a file"*)
+ *"ko: file not found"*)
;;
*)
- atf_fail "expected 'not a file', got: ${output}"
+ atf_fail "expected 'file not found', got: ${output}"
;;
esac
}
+atf_test_case no_existence_oracle
+no_existence_oracle_head()
+{
+ atf_set "descr" "Missing and non-regular files are indistinguishable"
+}
+no_existence_oracle_body()
+{
+ mkdir repo
+ mkdir repo/dir
+ missing=$(serve "get missing.pkg 0\nquit\n" repo)
+ nonreg=$(serve "get dir 0\nquit\n" repo)
+ [ "${missing}" = "${nonreg}" ] ||
+ atf_fail "responses differ: '${missing}' vs '${nonreg}'"
+}
+
atf_test_case path_traversal
path_traversal_head()
{
@@ -271,6 +286,7 @@ atf_init_test_cases()
atf_add_test_case get_file_leading_slash
atf_add_test_case get_file_uptodate
atf_add_test_case get_directory
+ atf_add_test_case no_existence_oracle
atf_add_test_case get_missing_age
atf_add_test_case get_bad_age
atf_add_test_case get_empty_arg