aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormerakor <cem@ckyln.com>2020-06-09 23:33:03 +0000
committermerakor <cem@ckyln.com>2020-06-09 23:33:03 +0000
commit24b52d0b289a6ca1e5b7a135273230d4ecbf1635 (patch)
tree121ec08a198a47021099b7ff9536ea2429a463b8
parentc35529a60953990a603b85637fff050d8beb355d (diff)
downloadcpt-24b52d0b289a6ca1e5b7a135273230d4ecbf1635.tar.gz
kiss: fix possible pkg_swap issue by escaping regular expressions
FossilOrigin-Name: 812d38f6b1079178864bd88e2e35ea09e9a7e7ccda114d5fdc157fc3c5c36cf0
-rwxr-xr-xkiss15
1 files changed, 11 insertions, 4 deletions
diff --git a/kiss b/kiss
index e1a6775..6835f09 100755
--- a/kiss
+++ b/kiss
@@ -43,6 +43,13 @@ contains() {
case " $1 " in *" $2 "*) return 0; esac; return 1
}
+regesc() {
+ # Escape special regular expression characters as
+ # defined in POSIX BRE. '$.*[\^'
+ printf '%s\n' "$1" | sed 's|\\|\\\\|g;s|\[|\\[|g;s|\$|\\$|g;s|\.|\\.|g;s|\*|\\*|g;s|\^|\\^|g'
+}
+
+
prompt() {
# If a KISS_NOPROMPT variable is set, continue.
# This can be useful for installation scripts and
@@ -940,8 +947,8 @@ pkg_swap() {
die "Alternative '$1 $2' doesn't exist"
if [ -f "$2" ]; then
- # Figure out which package owns the file we are going to
- # swap for another package's.
+ # Figure out which package owns the file we are going to swap for
+ # another package's.
#
# Print the full path to the manifest file which contains
# the match to our search.
@@ -960,7 +967,7 @@ pkg_swap() {
# its manifest file to reflect this. We then resort this file
# so no issues arise when removing packages.
cp -Pf "$KISS_ROOT/$2" "$pkg_owns>${alt#*>}"
- sed "s#^$2#${PWD#$KISS_ROOT}/$pkg_owns>${alt#*>}#" \
+ sed "s#^$(regesc "$2")#${PWD#$KISS_ROOT}/$pkg_owns>${alt#*>}#" \
"../installed/$pkg_owns/manifest" |
sort -r -o "../installed/$pkg_owns/manifest"
fi
@@ -968,7 +975,7 @@ pkg_swap() {
# Convert the desired alternative to a real file and rewrite
# the manifest file to reflect this. The reverse of above.
mv -f "$alt" "$KISS_ROOT/$2"
- sed "s#^${PWD#$KISS_ROOT}/$alt#$2#" "../installed/$1/manifest" |
+ sed "s#^${PWD#$KISS_ROOT}/$(regesc "$alt")#$2#" "../installed/$1/manifest" |
sort -r -o "../installed/$1/manifest"
}