zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] prevent parameters leaking from various completers
@ 2017-12-26  2:17 Eric Cook
  2018-01-03 17:00 ` Oliver Kiddle
  2018-01-06  6:43 ` dana
  0 siblings, 2 replies; 4+ messages in thread
From: Eric Cook @ 2017-12-26  2:17 UTC (permalink / raw)
  To: zsh-workers

---
 Completion/BSD/Command/_portsnap   | 2 +-
 Completion/Linux/Command/_ipset    | 2 +-
 Completion/Linux/Command/_valgrind | 4 ++--
 Completion/Redhat/Command/_rpm     | 2 +-
 Completion/Solaris/Command/_prstat | 1 +
 Completion/Unix/Command/_arp       | 2 +-
 Completion/Unix/Command/_cvs       | 2 +-
 Completion/Unix/Command/_devtodo   | 2 +-
 Completion/Unix/Command/_ffmpeg    | 2 +-
 Completion/Unix/Command/_git       | 2 +-
 Completion/Unix/Command/_gpg       | 2 +-
 Completion/Unix/Command/_ruby      | 2 +-
 Completion/Unix/Command/_ssh       | 2 +-
 Completion/Unix/Command/_tr        | 2 +-
 Completion/Unix/Command/_whois     | 1 +
 Completion/Unix/Command/_yp        | 2 +-
 Completion/Unix/Command/_zfs       | 2 +-
 Completion/X/Command/_xset         | 2 +-
 Completion/Zsh/Command/_cd         | 2 +-
 19 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/Completion/BSD/Command/_portsnap b/Completion/BSD/Command/_portsnap
index 0803a842e..b8e1c2555 100644
--- a/Completion/BSD/Command/_portsnap
+++ b/Completion/BSD/Command/_portsnap
@@ -1,6 +1,6 @@
 #compdef portsnap
 
-local curcontext="$curcontext" state line
+local curcontext="$curcontext" state line flags
 typeset -A opt_args
 
 flags=(
diff --git a/Completion/Linux/Command/_ipset b/Completion/Linux/Command/_ipset
index 0d6afc08e..d05f13caf 100644
--- a/Completion/Linux/Command/_ipset
+++ b/Completion/Linux/Command/_ipset
@@ -1,7 +1,7 @@
 #compdef ipset
 
 local offset=0
-local -a args from_to hash cmds listopts
+local -a args from_to hash cmds listopts addopts
 
 _set_types () {
 	_values -S \  "Set type" \
diff --git a/Completion/Linux/Command/_valgrind b/Completion/Linux/Command/_valgrind
index 0284ff880..1ae228c94 100644
--- a/Completion/Linux/Command/_valgrind
+++ b/Completion/Linux/Command/_valgrind
@@ -1,8 +1,8 @@
 #compdef valgrind -value-,VALGRIND_OPTS,-default-
 
 local curcontext="$curcontext" state line
-local -a cmd common common_mem_null \
-  args args_{addrcheck,memcheck,cachegrind,helgrind,lackey,massif,none}
+local -a cmd common common_{mem_null,read_varinfo}
+local -a args args_{addrcheck,memcheck,cachegrind,helgrind,lackey,massif,none}
 
 cmd=(
   '1:command name:_command_names -e'
diff --git a/Completion/Redhat/Command/_rpm b/Completion/Redhat/Command/_rpm
index b24213e3c..a9306aa6c 100644
--- a/Completion/Redhat/Command/_rpm
+++ b/Completion/Redhat/Command/_rpm
@@ -45,7 +45,7 @@ _rpm () {
   local curcontext="$curcontext" state lstate line nm="$compstate[nmatches]"
   typeset -A opt_args
   local ret=1
-  local -a tmp expl commonopts selectopts
+  local -a tmp expl commonopts selectopts pathopts
 
   commonopts=(
     '(-v --verbose)--quiet[print as little as possible]'
diff --git a/Completion/Solaris/Command/_prstat b/Completion/Solaris/Command/_prstat
index 963fad649..1eb38845c 100644
--- a/Completion/Solaris/Command/_prstat
+++ b/Completion/Solaris/Command/_prstat
@@ -2,6 +2,7 @@
 
 _prstat()
 {
+	local d_opt sort_key
 	d_opt=(
 		"u"\:"seconds past the epoch"
 		"d"\:"standard date format"
diff --git a/Completion/Unix/Command/_arp b/Completion/Unix/Command/_arp
index 80e829022..5b047b2b8 100644
--- a/Completion/Unix/Command/_arp
+++ b/Completion/Unix/Command/_arp
@@ -2,7 +2,7 @@
 
 local state line expl curcontext="$curcontext" ret=1
 typeset -A opt_args
-local -a cmds args
+local -a cmds args vopt flags
 
 flags=( temp pub )
 cmds=(
diff --git a/Completion/Unix/Command/_cvs b/Completion/Unix/Command/_cvs
index 0552d2175..cba3eb773 100644
--- a/Completion/Unix/Command/_cvs
+++ b/Completion/Unix/Command/_cvs
@@ -882,7 +882,7 @@ _cvs_modified_entries() {
 }
 
 (( $+_cvs_ignore_default )) ||
-_cvs_ignore_default=(
+local _cvs_ignore_default=(
   RCS SCCS CVS CVS.adm RCSLOG 'cvslog.*' tags TAGS .make.state .nse_depinfo
   '*\~' '\#*' '.\#*' ',*' '_$*' '*$' '*.old' '*.bak' '*.BAK' '*.orig' '*.rej'
   '.del-*' '*.a' '*.olb' '*.o' '*.obj' '*.so' '*.exe' '*.Z' '*.elc' '*.ln'
diff --git a/Completion/Unix/Command/_devtodo b/Completion/Unix/Command/_devtodo
index 2380399b9..8363495cd 100644
--- a/Completion/Unix/Command/_devtodo
+++ b/Completion/Unix/Command/_devtodo
@@ -5,7 +5,7 @@ typeset -a arg_generic arg_add todo_opts \
            priorities
 typeset -A arg_pair arg_desc
 typeset -i i
-typeset expl
+typeset expl arg
 
 for ((i=2; i <= $#words; i++)) {
 	if [[ $words[$i] == '--database' ]]; then
diff --git a/Completion/Unix/Command/_ffmpeg b/Completion/Unix/Command/_ffmpeg
index d68a094d4..c0b229f35 100644
--- a/Completion/Unix/Command/_ffmpeg
+++ b/Completion/Unix/Command/_ffmpeg
@@ -100,7 +100,7 @@ typeset -A _ffmpeg_flags
 
 local -a _ffmpeg_argspecs
 {
-    local lastopt
+    local lastopt REPLY
     local lastopt_description
     local lastopt_takesargs
     local lastopt_type
diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 8e3b0eb3d..a46da5b3c 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -7727,7 +7727,7 @@ for file in ${^fpath}/_git-*~(*~|*.zwc)(-.N); do
     continue
   fi
 
-  local desc=
+  local desc= input
   integer i=1
   while read input; do
     if (( i == 2 )); then
diff --git a/Completion/Unix/Command/_gpg b/Completion/Unix/Command/_gpg
index 239a032a1..48a36eff2 100644
--- a/Completion/Unix/Command/_gpg
+++ b/Completion/Unix/Command/_gpg
@@ -1,7 +1,7 @@
 #compdef gpg gpgv gpg-zip gpg2=gpg
 
 local curcontext="$curcontext" state line expl ret=1
-local -a args allopts dups
+local -a args allopts dups extra
 typeset -A opt_args
 
 if [[ $service = gpg-zip ]]; then
diff --git a/Completion/Unix/Command/_ruby b/Completion/Unix/Command/_ruby
index bb0558fde..7f7af8776 100644
--- a/Completion/Unix/Command/_ruby
+++ b/Completion/Unix/Command/_ruby
@@ -2,7 +2,7 @@
 
 local curcontext="$curcontext" state line expl desc RUBY ret=1
 typeset -A opt_args
-local -a opts irb all common charsets suf
+local -a opts irb erb all common charsets suf
 
 all=(
   '*-r+[require the library before executing your script]:library name:->library'
diff --git a/Completion/Unix/Command/_ssh b/Completion/Unix/Command/_ssh
index 984c96e93..5bf28796f 100644
--- a/Completion/Unix/Command/_ssh
+++ b/Completion/Unix/Command/_ssh
@@ -4,7 +4,7 @@
 
 _ssh () {
   local curcontext="$curcontext" state line expl suf ret=1
-  local args common tmp p1 file cmn cmds sdesc
+  local args common common_transfer tmp p1 file cmn cmds sdesc
   typeset -A opt_args
 
   common=(
diff --git a/Completion/Unix/Command/_tr b/Completion/Unix/Command/_tr
index d55fab5ff..efa3d4c91 100644
--- a/Completion/Unix/Command/_tr
+++ b/Completion/Unix/Command/_tr
@@ -1,7 +1,7 @@
 #compdef tr
 
 local curcontext="$curcontext" state line expl ret=1
-local args variant
+local args variant k
 local -A descr
 descr=(
   -c '[complement characters specified by first string]'
diff --git a/Completion/Unix/Command/_whois b/Completion/Unix/Command/_whois
index 2dd04f9cd..a8180f60e 100644
--- a/Completion/Unix/Command/_whois
+++ b/Completion/Unix/Command/_whois
@@ -1,6 +1,7 @@
 #compdef whois fwhois
 
 _whois () {
+  local _whois_comp
   _whois_setup
   case "$0" in
   fwhois) _whois_fwhois;;
diff --git a/Completion/Unix/Command/_yp b/Completion/Unix/Command/_yp
index 104a0b4df..b7619a02e 100644
--- a/Completion/Unix/Command/_yp
+++ b/Completion/Unix/Command/_yp
@@ -1,6 +1,6 @@
 #compdef ypcat ypmatch yppasswd ypwhich ypset ypserv ypbind yppush yppoll ypxfr domainname
 
-local curcontext="$curcontext" line state expl ret=1
+local curcontext="$curcontext" line state expl ret=1 _yp_cache_nicks _yp_args
 typeset -A opt_args
 
 if (( ! $+_yp_cache_maps )); then
diff --git a/Completion/Unix/Command/_zfs b/Completion/Unix/Command/_zfs
index 553996da0..ce5df5877 100644
--- a/Completion/Unix/Command/_zfs
+++ b/Completion/Unix/Command/_zfs
@@ -6,7 +6,7 @@ _zfs() {
 	typeset -A opt_args
 	local -a subcmds rw_properties rw_propnames ro_properties create_properties
 	local -a share_nfs_ro_properties share_nfs_rw_properties
-	local -a share_smb_ro_properties share_nfs_rw_properties
+	local -a share_smb_ro_properties share_smb_rw_properties
 	local -a share_ro_properties share_rw_properties
 	local -a difffields delegatable_perms
 
diff --git a/Completion/X/Command/_xset b/Completion/X/Command/_xset
index 53ec635d4..b35a6466b 100644
--- a/Completion/X/Command/_xset
+++ b/Completion/X/Command/_xset
@@ -111,7 +111,7 @@ _regex_arguments _xset_parse \
   \) \#
 
 _xset () {
-  local expl allopts
+  local expl allopts opt
   typeset -A desc no eo
 
   desc=(
diff --git a/Completion/Zsh/Command/_cd b/Completion/Zsh/Command/_cd
index 6b8d7ebeb..46237e73d 100644
--- a/Completion/Zsh/Command/_cd
+++ b/Completion/Zsh/Command/_cd
@@ -22,7 +22,7 @@ _cd_options() {
 setopt localoptions nonomatch
 
 local expl ret=1 curarg
-integer argstart=2 noopts
+integer argstart=2 noopts match mbegin mend
 
 if (( CURRENT > 1 )); then
   # if not in command position, may have options.
-- 
2.14.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] prevent parameters leaking from various completers
  2017-12-26  2:17 [PATCH] prevent parameters leaking from various completers Eric Cook
@ 2018-01-03 17:00 ` Oliver Kiddle
  2018-01-04 14:07   ` Eric Cook
  2018-01-06  6:43 ` dana
  1 sibling, 1 reply; 4+ messages in thread
From: Oliver Kiddle @ 2018-01-03 17:00 UTC (permalink / raw)
  To: zsh-workers

On 25 Dec, Eric Cook wrote:
> +++ b/Completion/Unix/Command/_yp

> +local curcontext="$curcontext" line state expl ret=1 _yp_cache_nicks _yp_args

>  if (( ! $+_yp_cache_maps )); then

In this particular case, the use of a global variable as a cache was
intentional and the change actually breaks _yp completion.

Adding typeset -g makes the intention rather clearer. I also would
prefer _cache_ as the initial prefix on any such variable making it
easier to unset them en masse.

Caching _yp_args is fairly pointless. ypwhich is also fairly instant so
I'm not sure we gain much by caching that either but perhaps it
generates network traffic to the NIS master so I'll leave it for now. It
probably was slow enough in 2001 to justify the caching.

Oliver

PS. This reminds me that I was supposed to cleanup the caching
mechanism. I won't, however, have much time for a few weeks.

diff --git a/Completion/Unix/Command/_yp b/Completion/Unix/Command/_yp
index b7619a02e..efd9aae5f 100644
--- a/Completion/Unix/Command/_yp
+++ b/Completion/Unix/Command/_yp
@@ -1,25 +1,27 @@
 #compdef ypcat ypmatch yppasswd ypwhich ypset ypserv ypbind yppush yppoll ypxfr domainname
 
-local curcontext="$curcontext" line state expl ret=1 _yp_cache_nicks _yp_args
+local curcontext="$curcontext" line state expl args ret=1
 typeset -A opt_args
 
-if (( ! $+_yp_cache_maps )); then
-  _yp_cache_maps=( "${(@)${(@f)$(_call_program maps ypwhich -m)}%% *}" )
-  _yp_cache_nicks=( "${(@)${(@)${(@f)$(_call_program names ypwhich -x)}#*\"}%%\"*}" )
-  _yp_args=(
-    '(-x)-d[specify domain]:domain name' \
-    '(-x)-k[display keys]' \
-    '(-x)-t[inhibit nicknames]' \
-    '(: -d -k -t)-x[display nicknames]' \
-  )
+if (( ! $+_cache_yp_maps )); then
+  typeset -ga _cache_yp_maps _cache_yp_nicks
+  _cache_yp_maps=( "${(@)${(@f)$(_call_program maps ypwhich -m)}%% *}" )
+  _cache_yp_nicks=( "${(@)${(@)${(@f)$(_call_program names ypwhich -x)}#*\"}%%\"*}" )
 fi
 
+args=(
+  '(-x)-d[specify domain]:domain name' \
+  '(-x)-k[display keys]' \
+  '(-x)-t[inhibit nicknames]' \
+  '(: -d -k -t)-x[display nicknames]' \
+)
+
 case "$service" in
 ypcat)
-  _arguments -C -s "$_yp_args[@]" ':map name:->map' && ret=0
+  _arguments -C -s $args ':map name:->map' && ret=0
   ;;
 ypmatch)
-  _arguments -C -s "$_yp_args[@]" '::key map:->keymap' ':map name:->map' && 
+  _arguments -C -s $args '::key map:->keymap' ':map name:->map' &&
     ret=0
   ;;
 yppasswd)
@@ -96,9 +98,9 @@ if [[ "$state" = map* ]]; then
     # The `-M ...' allows `pa.n<TAB>' to complete to `passwd.byname'.
     _requested maps expl 'map name' \
         compadd -M 'l:.|by=by l:.|=by r:|.=* r:|=*' -a \
-                _yp_cache_maps && ret=0
+                _cache_yp_maps && ret=0
     _requested nicknames expl nicknames \
-        compadd -a _yp_cache_nicks && ret=0
+        compadd -a _cache_yp_nicks && ret=0
     (( ret )) || return 0
   done
 elif [[ "$state" = servers ]]; then


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] prevent parameters leaking from various completers
  2018-01-03 17:00 ` Oliver Kiddle
@ 2018-01-04 14:07   ` Eric Cook
  0 siblings, 0 replies; 4+ messages in thread
From: Eric Cook @ 2018-01-04 14:07 UTC (permalink / raw)
  To: zsh-workers

On 01/03/2018 12:00 PM, Oliver Kiddle wrote:
> Adding typeset -g makes the intention rather clearer. I also would
> prefer _cache_ as the initial prefix on any such variable making it
> easier to unset them en masse.

Having an completer create global parameters seems kinda dirty considering
zsh has the caching functions that could be used. The only way to invalidate
matches is to unset the parameter and that requires knowing the name, all after
realizing that the completer is caching results.

Is there an reason why the use-cache style is not true by default?

I was thinking of changing the functions that create parameters as an cache to
use the caching functions. then test if use-cache isn't set for the current context,
then set it to true.

So caching for those specific completers still happen without the user needing to do
anything and can still be invalidated after an period of time.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] prevent parameters leaking from various completers
  2017-12-26  2:17 [PATCH] prevent parameters leaking from various completers Eric Cook
  2018-01-03 17:00 ` Oliver Kiddle
@ 2018-01-06  6:43 ` dana
  1 sibling, 0 replies; 4+ messages in thread
From: dana @ 2018-01-06  6:43 UTC (permalink / raw)
  To: Eric Cook; +Cc: zsh-workers

On 25 Dec 2017, at 20:17, Eric Cook <llua@gmx.com> wrote:
>-  local desc=
>+  local desc= input

I noticed that this fouls up git completion. The first time i do `git add
whatever<TAB>`, it prints out a bunch of garbage (since this is happening in a
loop and typeset_silent isn't set). Fix attached.

Also, in _cd, we're marking match, mbegin, and mend as integers when they're
actually arrays. I don't think that will hurt anything, but...?

dana


diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index a46da5b3c..bf5c1e702 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -7727,7 +7727,7 @@ for file in ${^fpath}/_git-*~(*~|*.zwc)(-.N); do
     continue
   fi
 
-  local desc= input
+  local desc= input=
   integer i=1
   while read input; do
     if (( i == 2 )); then

diff --git a/Completion/Zsh/Command/_cd b/Completion/Zsh/Command/_cd
index 46237e73d..32f53a78b 100644
--- a/Completion/Zsh/Command/_cd
+++ b/Completion/Zsh/Command/_cd
@@ -21,8 +21,8 @@ _cd_options() {
 
 setopt localoptions nonomatch
 
-local expl ret=1 curarg
-integer argstart=2 noopts match mbegin mend
+local expl ret=1 curarg match mbegin mend
+integer argstart=2 noopts
 
 if (( CURRENT > 1 )); then
   # if not in command position, may have options.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-01-06  6:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-26  2:17 [PATCH] prevent parameters leaking from various completers Eric Cook
2018-01-03 17:00 ` Oliver Kiddle
2018-01-04 14:07   ` Eric Cook
2018-01-06  6:43 ` dana

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).