From 55c550b05dc8401a3862b80e564197de37ddb772 Mon Sep 17 00:00:00 2001 From: Ayush Agarwal Date: Wed, 8 Sep 2021 03:35:23 +0530 Subject: add validation check for PASSFILE and CHOICE rofi and bemenu don't prevent garbage input from getting allocated to the PASSFILE and CHOICE variables. We need to check for the validity of the user input and fail if needed. --- tessen | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/tessen b/tessen index 2d436e7..94f78ec 100755 --- a/tessen +++ b/tessen @@ -31,7 +31,7 @@ get_pass_file() { PASSFILE="$(printf '%s\n' "${tmp_pass_3[@]}" | "${BACKEND[@]}")" - if [[ -z "$PASSFILE" ]]; then + if ! [[ -e "$PASS_STORE/$PASSFILE".gpg ]]; then exit 1 fi } @@ -65,18 +65,36 @@ get_pass_data() { # get the key that the user chooses to copy choice_data_copy() { + local ch flag + flag="" + CHOICE="$(printf '%s\n' "username" "password" "${!PASSDATA_ARR[@]}" | "${BACKEND[@]}")" - if [[ -z "$CHOICE" ]]; then + for ch in "username" "password" "${!PASSDATA_ARR[@]}"; do + if [[ "$CHOICE" == "$ch" ]]; then + flag=1 + fi + done + + if [[ "$flag" -ne 1 ]]; then exit 1 fi } # get the key that the user chooses to autotype choice_data_autotype() { + local ch flag + flag="" + CHOICE="$(printf '%s\n' "autotype" "username" "password" "${!PASSDATA_ARR[@]}" | "${BACKEND[@]}")" - if [[ -z "$CHOICE" ]]; then + for ch in "autotype" "username" "password" "${!PASSDATA_ARR[@]}"; do + if [[ "$CHOICE" == "$ch" ]]; then + flag=1 + fi + done + + if [[ "$flag" -ne 1 ]]; then exit 1 fi } -- cgit v1.2.3