diff options
author | Ayush Agarwal <ayush@fastmail.in> | 2021-09-08 03:35:23 +0530 |
---|---|---|
committer | Ayush Agarwal <ayush@fastmail.in> | 2021-09-08 03:35:23 +0530 |
commit | 55c550b05dc8401a3862b80e564197de37ddb772 (patch) | |
tree | 291b3b9d2fe2eb73c4c708fb793dadcd22b97e05 | |
parent | fcbc0ff1676a720e48022157b9c7f72e5bfc61ed (diff) |
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.
-rwxr-xr-x | tessen | 24 |
1 files changed, 21 insertions, 3 deletions
@@ -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 } |