From 3d97ce34caefbee5263d4814238a2394274b4d6d Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sat, 21 Jun 2014 12:20:17 -0400 Subject: [PATCH] validate arguments to be of the allowable formats Addresses FS#40087. --- abs.in | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/abs.in b/abs.in index e98c463..ffe1105 100644 --- a/abs.in +++ b/abs.in @@ -54,6 +54,21 @@ error() { printf "==> ERROR: ${mesg}\n" "$@" >&2 } +die() { + error "$@" + exit 1 +} + +in_array() { + local i + + for i in "${@:2}"; do + [[ $1 = "$i" ]] && return 0 + done + + return 1 +} + ## # Source configuration ## @@ -240,9 +255,16 @@ while true; do shift done -if [ "$#" -gt "0" ]; then +if (( $# > 0 )); then + for arg; do + # arguments must be of the format 'repo' or 'repo/pkg' + if [[ $arg = */* ]] || in_array "$arg" "${REPOS[@]}"; then + REPOS=("$arg") + else + die '%s is not a valid repository' "$arg" + fi + done CLPARAM=1 - REPOS=("$@") fi ## -- 2.0.0