From 7d32ad499913ace42245965d1c0dd12c3e073617 Mon Sep 17 00:00:00 2001 From: Sandeep Kumar Date: Thu, 5 Oct 2023 09:43:14 +0530 Subject: [PATCH] Added Sanitization for the input file for termux-open command --- scripts/termux-open.in | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/scripts/termux-open.in b/scripts/termux-open.in index e2cf392..9850259 100644 --- a/scripts/termux-open.in +++ b/scripts/termux-open.in @@ -40,6 +40,27 @@ if [ -f "$FILE" ]; then FILE=$(realpath "$FILE") fi +urlencode() { + 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" +} + +FILE=$(urlencode "$FILE") + am broadcast --user 0 \ -a $ACTION \ -n com.termux/com.termux.app.TermuxOpenReceiver \