-
Notifications
You must be signed in to change notification settings - Fork 126
Added Sanitization for the input file for termux-open command #58
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
base: master
Are you sure you want to change the base?
Added Sanitization for the input file for termux-open command #58
Conversation
If you always do encoding, you will break paths if they were already encoded by user before passing to Moreover, it's best not to encode yourself, encoding algorithms are very complex. You can use if [ "$ENCODE" = "1" ]; then
# Encode FILE with curl. sed replaced trailing newline and the "/?" prefix.
# - https://stackoverflow.com/a/10797966
FILE="$(printf "%s" "$FILE" | { curl -Gs -w %{url_effective} --data-urlencode @- ./ || :; } | sed -e "s/%0[aA]$//; s/^[^?]*?\(.*\)/\1/")"
fi Also commit format must be as per repo git history. Use
|
string="$1" | ||
length=$(echo "$string" | wc -c) | ||
length=$((length - 1)) | ||
encoded="" | ||
|
||
i=1 | ||
while [ "$i" -le "$length" ]; do | ||
char=$(echo "$string" | cut -c "$i") | ||
case "$char" in | ||
[a-zA-Z0-9.~_-]) encoded="$encoded$char";; | ||
*) encoded="$encoded%$(printf "%02X" "'$char")";; | ||
esac | ||
i=$((i + 1)) | ||
done | ||
|
||
echo "$encoded" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be done much easier without invoking external commands lots of times.
string="$1" | |
length=$(echo "$string" | wc -c) | |
length=$((length - 1)) | |
encoded="" | |
i=1 | |
while [ "$i" -le "$length" ]; do | |
char=$(echo "$string" | cut -c "$i") | |
case "$char" in | |
[a-zA-Z0-9.~_-]) encoded="$encoded$char";; | |
*) encoded="$encoded%$(printf "%02X" "'$char")";; | |
esac | |
i=$((i + 1)) | |
done | |
echo "$encoded" | |
for ((i=0; i<${#1}; i++)); do | |
case "${1:i:1}" in | |
[a-zA-Z0-9.~_-]) printf '%s' "${1:i:1}" ;; | |
*) printf '%%%02X' "'${1:i:1}" ;; | |
esac | |
done | |
echo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, it is regular /bin/sh, not a bash. Right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we switch to bash here?
The termux-open command had no sanitization for the input file, which prevented it from opening files containing % characters, this P.R. adds that sanitization.
termux/termux-app#3250