[pacman-dev] [PATCH 3/3] paccache: verify nonnegative integer for -k option

Dave Reisner d at falconindy.com
Wed Sep 28 13:52:20 EDT 2011


On Thu, Sep 29, 2011 at 12:58:59AM +0800, lolilolicon wrote:
> Allow leading zeros, but always treat it as decimal.

If this was your goal, you missed. 'keep' is declared with an integer
attribute meaning that all conversions to decimal are done at
assignment, i.e.

$ declare -i keep=015
# declare -p keep
declare -i keep="13"

> Also quote right side of [[ expression ]] when the != or == operator is
> used, unless a pattern is intended.

This really should be separate commits, or the first line should be a
more accurate summation of the changes involved.

> Signed-off-by: lolilolicon <lolilolicon at gmail.com>
> ---
>  contrib/paccache.in |    6 ++++--
>  1 files changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/contrib/paccache.in b/contrib/paccache.in
> index 11b7bbb..c86ea31 100755
> --- a/contrib/paccache.in
> +++ b/contrib/paccache.in
> @@ -153,7 +153,7 @@ summarize() {
>  			while read -r pkg; do
>  				if (( verbose >= 3 )); then
>  					[[ $pkg =~ $pkg_re ]] && name=${BASH_REMATCH[1]} arch=${BASH_REMATCH[2]}
> -					if [[ -z $seen || $seenarch != $arch || $seen != $name ]]; then
> +					if [[ -z $seen || $seenarch != "$arch" || $seen != "$name" ]]; then

I'm not saying this is wrong, but there'd have to be some seriously
screwed up packages in your cache for this quoting to matter.

>  						printf '%s (%s):\n' "$name" "$arch"
>  					fi
>  					printf '  %s\n' "$pkg"
> @@ -220,8 +220,10 @@ while getopts ':a:c:dfhi:k:m:rsuvz' opt; do
>  			 blacklist+=("${ign[@]}")
>  			unset i ign ;;
>  		k) keep=$OPTARG
> -			if [[ $keep != $OPTARG ]] || (( keep < 0 )); then
> +			if [[ -z $keep || -n ${keep//[0-9]/} ]]; then
>  				die 'argument to option -k must be a non-negative integer'
> +			else
> +				keep=$(( 10#$keep ))
>  			fi ;;
>  		m) move=1 movedir=$OPTARG ;;
>  		r) delete=1 ;;
> -- 
> 1.7.6.4
> 


More information about the pacman-dev mailing list