From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23945 invoked by alias); 9 Mar 2015 19:57:26 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 34693 Received: (qmail 11183 invoked from network); 9 Mar 2015 19:57:25 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= daniel.shahaf.name; h=x-sasl-enc:date:from:to:cc:subject :message-id:references:mime-version:content-type:in-reply-to; s= mesmtp; bh=7GzkhQ8KjgGbsJ2bsFbaew2amyg=; b=teAOip4BqRlJF+r4Sp/sx dwBsAy8xXfcejW5gPj2+Znkmhd0nE5Ck0IxQMAHj9ARo+LEOxVDznwHwApu/llRD SBxv2yQXeytwfc8obOwUQxMP0rjCFZsIF8zF07tB6uInv3iIloUZqHJyf3pA0R1W 8gPlltdal7zgLVgLishJFY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=x-sasl-enc:date:from:to:cc:subject :message-id:references:mime-version:content-type:in-reply-to; s= smtpout; bh=7GzkhQ8KjgGbsJ2bsFbaew2amyg=; b=VsdQQ8KjaSj62px4KuQu ZZE1Moa708vJ0ERTf4EP/xX4NUxunbKYMXjf3KBM+jbDMkQNtd3icbzMyfE3E4OX lM5KyLSSOVCfFt0s8NxYDiQNcS3sLjLc9KXQiLZoT3W7321PAJ7DKepLhyRJO4c5 ctWUa2tRDUERm4CJYSN5eeY= X-Sasl-enc: b1CiqF0GfII96BjProRTrfrN8gqqXhuM0zTzG1E3wwz/ 1425931042 Date: Mon, 9 Mar 2015 19:57:19 +0000 From: Daniel Shahaf To: Bart Schaefer Cc: zsh-workers@zsh.org Subject: Re: [PATCH] sudo strace -e Message-ID: <20150309195719.GC2607@tarsus.local2> References: <20150307042733.GF2206@tarsus.local2> <150306234225.ZM12537@torch.brasslantern.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="huq684BweRXVnRxX" Content-Disposition: inline In-Reply-To: <150306234225.ZM12537@torch.brasslantern.com> User-Agent: Mutt/1.5.21 (2010-09-15) --huq684BweRXVnRxX Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Bart Schaefer wrote on Fri, Mar 06, 2015 at 23:42:25 -0800: > On Mar 7, 4:27am, Daniel Shahaf wrote: > } Subject: [PATCH] sudo strace -e > } > } Is there a smarter way to detect whether -e was passed to sudo? > > Perhaps > > (( $words[(i)-e] < $words[(i)[^-]*] )) > > would do? That is, the -e appears before the first word that doesn't > begin with a hyphen. The way (i) works in subscripts, the above will > always be true if all the words begin with a hyphen. Good idea, but the RHS will evaluate to 1 since the command word doesn't begin with a hyphen. This seems to work (with extended_glob): (( $words[(i)-e] < $words[(i)^(*sudo|-[^-]*)] )) > A slight tweak might fix the problem with -Ae not working: > > (( $words[(i)-(e|Ae)] < $words[(i)[^-]*] )) -Ae was just an example, 'sudoedit' takes a few other flags (equivalent to getopts "AnSC:g:p:u:"). As you can see, some of these flags take arguments, which may be in separate words. And then there's the '--' arguments terminator. I'm not going to try and handle all those cases. (How common is sudoedit -[x] to begin with, anyway?) The right way is for _arguments to extract that information and provide it back to _sudo. (I don't think that's currently possible; the -> syntax is in the {action} field and -e doesn't take an argument, so there's no way to specify an {action} for it.) Cheers, Daniel --huq684BweRXVnRxX Content-Type: text/x-patch; charset=us-ascii Content-Disposition: attachment; filename="0001-_strace-Fix-variable-leakage-of-sys_calls.patch" >>From 46aed0420bb7b01db8a7ad60fbd2e6d78a0ec087 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 7 Mar 2015 15:28:27 +0000 Subject: [PATCH 1/2] _strace: Fix variable leakage of $sys_calls --- Completion/Linux/Command/_strace | 1 + 1 file changed, 1 insertion(+) diff --git a/Completion/Linux/Command/_strace b/Completion/Linux/Command/_strace index 45ebfcf..d6dabfd 100644 --- a/Completion/Linux/Command/_strace +++ b/Completion/Linux/Command/_strace @@ -5,6 +5,7 @@ # - allow negated calls (e.g. -e!write) _sys_calls () { local expl + local -a sys_calls sys_calls=(_llseek _newselect _sysctl accept access acct adjtimex afs_syscall alarm bdflush bind break brk cacheflush -- 1.9.1 --huq684BweRXVnRxX Content-Type: text/x-patch; charset=us-ascii Content-Disposition: attachment; filename="0002-sudo-completion-Don-t-false-positive-sudo-e-detectio.patch" >>From 8baf05d0ad7ea482df6329da13c67695085a0d87 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 7 Mar 2015 15:31:14 +0000 Subject: [PATCH 2/2] sudo completion: Don't false positive 'sudo -e' detection --- Completion/Unix/Command/_sudo | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Completion/Unix/Command/_sudo b/Completion/Unix/Command/_sudo index ee238b4..63ac37f 100644 --- a/Completion/Unix/Command/_sudo +++ b/Completion/Unix/Command/_sudo @@ -1,5 +1,7 @@ #compdef sudo sudoedit +setopt localoptions extended_glob + local environ e local -a args @@ -29,7 +31,12 @@ args=( '(-v --validate)'{-v,--validate}"[update user's timestamp without running a command]" ) -if [[ $service = sudoedit || -n ${words[(r)-e]} ]]; then +# Does -e appears before the first word that doesn't begin with a hyphen? +# The way (i) works in subscripts, the test will always be true if all the +# words begin with a hyphen. +# +# TODO: use _arguments' $opt_args to detect the cases '-u jrandom -e' and '-Ae' +if [[ $service = sudoedit ]] || (( $words[(i)-e] < $words[(i)^(*sudo|-[^-]*)] )) ; then args=( -A "-*" $args '!(-V --version -h --help)-e' '*:file:_files' ) else args+=( -- 1.9.1 --huq684BweRXVnRxX--