V8.03.256.2025.06.02

Signed-off-by: Marc S. Weidner <msw@coresecret.dev>
This commit is contained in:
2025-06-02 20:11:58 +02:00
parent a0d6e1a29c
commit c3a67f3d41
2 changed files with 30 additions and 11 deletions

View File

@@ -19,7 +19,7 @@ arg_check() {
declare a
declare sanitized_args=()
for a in "$@"; do
sanitized_args+=( "$(sanitize_arg "${a}")" )
sanitized_args+=("$( sanitize_arg "${a}")")
done
set -- "${sanitized_args[@]}"
}
@@ -33,13 +33,32 @@ arg_check() {
# $1: Argument to check
#######################################
sanitize_arg() {
declare input="$1"
# Define allowed characters:
# letters, digits, dot, underscore, slash, equals, [, ], colon, double-quote, hyphen, space.
declare input="${1}"
declare disallowed_ctrl=""
### Step 1: Check for control characters
if printf '%s' "${input}" | grep -qP '[[:cntrl:]]'; then
disallowed_ctrl=$(printf '%s' "${input}" | sed -n 's/[^[:cntrl:]]//gp' | sed $'s/./&\\n/g' \
| while read -r c; do printf "%02X " "'$c"; done)
{
printf "❌ Control character : '%s'. \n" "${disallowed_ctrl}"
printf "❌ in argument : '%s'. \n" "${input}"
printf "❌ Allowed Characters : 'a-z A-Z 0-9 . _ / = [ ] : \" - + space' \n"
printf "\n"
} >> "${LOG_ERROR}"
boot_screen_cleaner
printf "\e[91m❌ Control character : '%s'. \e[0m\n" "${disallowed_ctrl}" >&2
printf "\e[91m❌ in argument : '%s'. \e[0m\n" "${input}" >&2
printf "\e[91m❌ Allowed Characters : 'a-z A-Z 0-9 . _ / = [ ] : \" - + space' \e[0m\n" >&2
# shellcheck disable=SC2162
read -p $'\e[92m✅ Press \'ENTER\' to exit the script ... \e[0m'
exit "${ERR_INVLD_CHAR}"
fi
### Step 2: Define allowed characters:
### letters, digits, dot, underscore, slash, equals, [, ], colon, double-quote, hyphen, space.
declare allowed='a-zA-Z0-9._/=\[\]:"\-+ '
declare disallowed
disallowed=$(printf '%s' "${input}" | tr -d "${allowed}")
if [[ -n ${disallowed} ]]; then
{
printf "❌ Invalid character : '%s'. \n" "${disallowed//?/& }"
@@ -66,9 +85,9 @@ sanitize_arg() {
#######################################
sanitize_string() {
declare input="$1"
# Define allowed characters:
# letters, digits, dot, underscore, slash, equals, [, ], colon, double-quote, hyphen, space.
declare allowed='a-zA-Z0-9._/=\[\]:"\- '
### Define allowed characters:
### letters, digits, dot, underscore, slash, equals, [, ], colon, double-quote, hyphen, space.
declare allowed='a-zA-Z0-9._/=\[\]:"\-+ '
printf '%s' "${input}" | tr -cd "${allowed}"
}
@@ -79,7 +98,7 @@ sanitize_string() {
#######################################
sanitize_shell_literal() {
declare input="$1"
# %q quotes the string so that the shell re-reads it as the original literal
### %q quotes the string so that the shell re-reads it as the original literal
printf '%q' "${input}"
}
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=sh