[pacman-dev] [PATCH 1/3] paccache: allow strictly integer for -k option
Verify the argument to -k is a non-negative integer. Leading zeros are simply tripped. 'declare -i keep' allowed the argument to -k to be any arithmetic evaluation expression. The simple assignment 'keep=$OPTARG' triggers arithmetic evaluation implicitly, which can either consume a huge amount of resources with input such as '2**2**32' or immediately produce an error on invalid input. Instead, we simply 'declare -- keep' and avoid all that. Signed-off-by: lolilolicon <lolilolicon@gmail.com> --- contrib/paccache.in | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-) diff --git a/contrib/paccache.in b/contrib/paccache.in index 11b7bbb..7c35cf2 100755 --- a/contrib/paccache.in +++ b/contrib/paccache.in @@ -21,8 +21,8 @@ shopt -s extglob declare -a candidates=() cmdopts=() whitelist=() blacklist=() -declare -i delete=0 dryrun=0 filecount=0 keep=3 move=0 totalsaved=0 -declare cachedir=@localstatedir@/cache/pacman/pkg delim=$'\n' movedir= scanarch= +declare -i delete=0 dryrun=0 filecount=0 move=0 totalsaved=0 +declare cachedir=@localstatedir@/cache/pacman/pkg delim=$'\n' keep=3 movedir= scanarch= msg() { local mesg=$1; shift @@ -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
Declare and initialize integer variables 'needsroot' and 'verbose'. Don't use the fact that (( undefined_variable )) evaluates to 0. Signed-off-by: lolilolicon <lolilolicon@gmail.com> --- contrib/paccache.in | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/contrib/paccache.in b/contrib/paccache.in index 7c35cf2..e5cac7d 100755 --- a/contrib/paccache.in +++ b/contrib/paccache.in @@ -21,7 +21,7 @@ shopt -s extglob declare -a candidates=() cmdopts=() whitelist=() blacklist=() -declare -i delete=0 dryrun=0 filecount=0 move=0 totalsaved=0 +declare -i delete=0 dryrun=0 filecount=0 move=0 needsroot=0 totalsaved=0 verbose=0 declare cachedir=@localstatedir@/cache/pacman/pkg delim=$'\n' keep=3 movedir= scanarch= msg() { -- 1.7.6.4
Always quote the right-hand side of expression when the == or != operator is used, unless intended as a pattern. Signed-off-by: lolilolicon <lolilolicon@gmail.com> --- contrib/paccache.in | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/contrib/paccache.in b/contrib/paccache.in index e5cac7d..4e185c2 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 printf '%s (%s):\n' "$name" "$arch" fi printf ' %s\n' "$pkg" -- 1.7.6.4
On Thu, Sep 29, 2011 at 10:45 AM, lolilolicon <lolilolicon@gmail.com> wrote:
Verify the argument to -k is a non-negative integer. Leading zeros are simply tripped.
Oops, sorry s/tripped/stripped/ there. Dave, will you correct this typo for me, or should I resend the patch? May I ask how should I resend a v2 patch in this case? Something like: git send-email --in-reply-to '<message-id_of_the_origial_email>' v2.patch Is that OK or is there a better way to do it?
On Thu, Sep 29, 2011 at 10:58:14AM +0800, lolilolicon wrote:
On Thu, Sep 29, 2011 at 10:45 AM, lolilolicon <lolilolicon@gmail.com> wrote:
Verify the argument to -k is a non-negative integer. Leading zeros are simply tripped.
Oops, sorry s/tripped/stripped/ there. Dave, will you correct this typo for me, or should I resend the patch?
done. pushed to my paccache branch on GH.
May I ask how should I resend a v2 patch in this case? Something like:
git send-email --in-reply-to '<message-id_of_the_origial_email>' v2.patch
Is that OK or is there a better way to do it?
Yep, that's fine. d
participants (2)
-
Dave Reisner
-
lolilolicon