commit 55c550b05dc8401a3862b80e564197de37ddb772
parent fcbc0ff1676a720e48022157b9c7f72e5bfc61ed
Author: Ayush Agarwal <ayush@fastmail.in>
Date: Wed, 8 Sep 2021 03:35:23 +0530
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.
Diffstat:
| M | tessen | | | 24 | +++++++++++++++++++++--- |
1 file changed, 21 insertions(+), 3 deletions(-)
diff --git 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
}