Disallow refs starting with a non-letter or digit
Change the regexp for validating refs to require at least one letter or digit
before allowing the other special chars in the set `[.-_]`. Names that start
with `.` are traditionally Unix hidden files; let's ignore them under the
assumption they're metadata for some other tool, and we don't want to
potentially conflict with the special `.` and `..` Unix directory entries.
Further, names starting with `-` are problematic for Unix cmdline option
processing; there's no good reason to support that. Finally, disallow `_` just
on general principle - it's simpler to say that ref identifiers must start with
a letter or digit.
We also ignore any existing files (that might be previously created refs) that
start with `.` in the `refs/` directory - there's a Red Hat tool for content
management that injects `.rsync` files, which is why this patch was first
written.
V1: Update to ban all refs starting with a non-letter/digit, and
also add another call to `ostree_validate_rev` in the pull
code.
Closes: https://github.com/ostreedev/ostree/issues/1285
Closes: #1286
Approved by: jlebon
This commit is contained in:
1 parent
3f3d3d64ac
commit
e466e482b1
5 files changed
+69
-2
No files matched your search
+30
-1
@@ -23,7 +23,7 @@ set -euo pipefail
|
||||
|
||||
setup_fake_remote_repo1 "archive"
|
||||
|
||||
echo '1..2'
|
||||
echo '1..5'
|
||||
|
||||
cd ${test_tmpdir}
|
||||
mkdir repo
|
||||
@@ -88,6 +88,35 @@ if ${CMD_PREFIX} ostree --repo=repo refs foo/ctest --create=ctest; then
|
||||
assert_not_reached "refs --create unexpectedly succeeded in overwriting an existing prefix!"
|
||||
fi
|
||||
|
||||
# https://github.com/ostreedev/ostree/issues/1285
|
||||
# One tool was creating .latest_rsync files in each dir, let's ignore stuff like
|
||||
# that.
|
||||
echo '👻' > repo/refs/heads/.spooky_and_hidden
|
||||
${CMD_PREFIX} ostree --repo=repo refs > refs.txt
|
||||
assert_not_file_has_content refs.txt 'spooky'
|
||||
${CMD_PREFIX} ostree --repo=repo refs ctest --create=exampleos/x86_64/standard
|
||||
echo '👻' > repo/refs/heads/exampleos/x86_64/.further_spooky_and_hidden
|
||||
${CMD_PREFIX} ostree --repo=repo refs > refs.txt
|
||||
assert_file_has_content refs.txt 'exampleos/x86_64/standard'
|
||||
assert_not_file_has_content refs.txt 'spooky'
|
||||
rm repo/refs/heads/exampleos -rf
|
||||
echo "ok hidden refs"
|
||||
|
||||
for ref in '.' '-' '.foo' '-bar' '!' '!foo'; do
|
||||
if ${CMD_PREFIX} ostree --repo=repo refs ctest --create=${ref} 2>err.txt; then
|
||||
fatal "Created ref ${ref}"
|
||||
fi
|
||||
assert_file_has_content err.txt 'Invalid ref'
|
||||
done
|
||||
echo "ok invalid refs"
|
||||
|
||||
for ref in 'org.foo.bar/x86_64/standard-blah'; do
|
||||
ostree --repo=repo refs ctest --create=${ref}
|
||||
ostree --repo=repo rev-parse ${ref} >/dev/null
|
||||
ostree --repo=repo refs --delete ${ref}
|
||||
done
|
||||
echo "ok valid refs with chars '._-'"
|
||||
|
||||
#Check to see if any uncleaned tmp files were created after failed --create
|
||||
${CMD_PREFIX} ostree --repo=repo refs | wc -l > refscount.create1
|
||||
assert_file_has_content refscount.create1 "^5$"
|
||||
|
||||
Reference in new issue
Block a user