about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2008-09-27 19:57:25 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2008-09-27 19:57:25 +0000
commit4a34c9628942a3631500e51b57ce4ccb4ac77fb4 (patch)
treeb1c0d6eba97bf68f361093f91e27cb4eddade013
parent4ba03217caf578fab92202cd853d8de35aa047ed (diff)
downloadzsh-4a34c9628942a3631500e51b57ce4ccb4ac77fb4.tar.gz
zsh-4a34c9628942a3631500e51b57ce4ccb4ac77fb4.tar.xz
zsh-4a34c9628942a3631500e51b57ce4ccb4ac77fb4.zip
25755/25756: Jörg Sommer: improved handling of module arguments
25759: fix dynamic named directory crash, static named directory consistency
-rw-r--r--ChangeLog11
-rw-r--r--Completion/Linux/Command/_modutils24
-rw-r--r--Doc/Zsh/expn.yo5
-rw-r--r--Src/builtin.c16
-rw-r--r--Src/subst.c8
5 files changed, 48 insertions, 16 deletions
diff --git a/ChangeLog b/ChangeLog
index 833534d5f..84a034b2a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2008-09-27  Peter Stephenson  <p.w.stephenson@ntlworld.com>
+
+	* Jörg Sommer: 25755, with tweak from 25756:
+	Completion/Linux/Command/_modutils (args): improved handling
+	of module arguments.
+
+	* 25759: Doc/Zsh/expn.yo, Src/builtin.c, Src/subst.c: fix crash
+	after failed dynamic named directory expansion; clarify the
+	fact that static named directories can contain only
+	alphanumerics, `_', `-' or `.'.
+
 2008-09-26  Clint Adams  <clint@zsh.org>
 
 	* Mikael Magnusson: 25617: Completion/Unix/Command/_vim:
diff --git a/Completion/Linux/Command/_modutils b/Completion/Linux/Command/_modutils
index 732290363..e03b47184 100644
--- a/Completion/Linux/Command/_modutils
+++ b/Completion/Linux/Command/_modutils
@@ -36,7 +36,7 @@ case "$service" in
       '(-C --config)'{-C,--config}'[specify config file]:config file:_files' \
       "(-r --remove -l --list -t --type -a --all $ign)"{-r,--remove}'[remove module (stacks)]' \
       "(* -l --list -r --remove $ign)"{-l,--list}'[list matching modules]' \
-      "(-c $ign)1:modules:->all_modules" \
+      "(-c $ign)1:modules:->loadable_modules" \
       "(-c -l --list -t --type $ign)*:params:->params" && ret=0
       
       [[ -n $state ]] && (( $+opt_args[-r] )) && state=loaded_modules        
@@ -60,23 +60,31 @@ case "$service" in
 esac 
 
 case "$state" in
-  loaded_modules)
+  loaded_modules|loadable_modules)
     if [[ -r /proc/modules ]]; then
-     modules=(${${(f)"$(</proc/modules)"}%% *})
+     loaded_modules=(${${(f)"$(</proc/modules)"}%% *})
     elif [[ -x /sbin/lsmod ]]; then
-     modules=(${${(f)"$(/sbin/lsmod)"}[2,-1]%% *})
+     loaded_modules=(${${(f)"$(/sbin/lsmod)"}[2,-1]%% *})
     else
      return 1
     fi
-    
-    _wanted modules expl 'loaded module' compadd -a modules && return
-  ;;
+
+    if [[ $state = loaded_modules ]]; then
+        _wanted modules expl 'loaded module' compadd -a loaded_modules && return
+        return ret
+    fi
+  ;&
 
   all_modules)
     modules=( ${${${${(f)"$(_call_program modules ${(M)words[1]##*/}modprobe -l 2>/dev/null)"}:#}##*/}%%.*} )
+
+    if [[ $state = loadable_modules ]]; then
+        modules=( ${modules:#(${(j:|:)~${=loaded_modules//_/-}})} )
+    fi
+
     _tags files modules
     while _tags; do
-      _requested files expl "module file"  _files && ret=0
+      _requested files expl "module file"  _files -g '*.ko' && ret=0
       _requested modules expl module compadd -a modules && ret=0
     done
   ;;
diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo
index ec528313f..b16ec4b5b 100644
--- a/Doc/Zsh/expn.yo
+++ b/Doc/Zsh/expn.yo
@@ -1375,13 +1375,16 @@ subsect(Static named directories)
 cindex(directories, named, static)
 cindex(named directories, static)
 cindex(static named directories)
-A `tt(~)' followed by anything not already covered is looked up as a
+A `tt(~)' followed by anything not already covered consisting
+of any number of alphanumeric characters or underscore (`tt(_)'),
+hyphen (`tt(-)'), or dot (`tt(.)') is looked up as a
 named directory, and replaced by the value of that named directory if found.
 Named directories are typically home directories for users on the system.
 They may also be defined if the text after the `tt(~)' is the name
 of a string shell parameter whose value begins with a `tt(/)'.
 Note that trailing slashes will be removed from the path to the directory
 (though the original parameter is not modified).
+
 It is also possible to define directory names using the tt(-d) option to the
 tt(hash) builtin.
 
diff --git a/Src/builtin.c b/Src/builtin.c
index d274ef9ad..02f843bf8 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -3262,9 +3262,19 @@ bin_hash(char *name, char **argv, Options ops, UNUSED(int func))
 		/* The argument is of the form foo=bar, *
 		 * so define an entry for the table.    */
 		if(OPT_ISSET(ops,'d')) {
-		    Nameddir nd = hn = zshcalloc(sizeof *nd);
-		    nd->node.flags = 0;
-		    nd->dir = ztrdup(asg->value);
+		    /* shouldn't return NULL if asg->name is not NULL */
+		    if (*itype_end(asg->name, IUSER, 0)) {
+			zwarnnam(name,
+				 "invalid character in directory name: %s",
+				 asg->name);
+			returnval = 1;
+			argv++;
+			continue;
+		    } else {
+			Nameddir nd = hn = zshcalloc(sizeof *nd);
+			nd->node.flags = 0;
+			nd->dir = ztrdup(asg->value);
+		    }
 		} else {
 		    Cmdnam cn = hn = zshcalloc(sizeof *cn);
 		    cn->node.flags = HASHED;
diff --git a/Src/subst.c b/Src/subst.c
index caa2ecfda..95369fdf6 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -529,7 +529,7 @@ filesubstr(char **namptr, int assign)
 
     if (*str == Tilde && str[1] != '=' && str[1] != Equals) {
 	Shfunc dirfunc;
-	char *ptr, *tmp, *res;
+	char *ptr, *tmp, *res, *ptr2;
 	int val;
 
 	val = zstrtol(str + 1, &ptr, 10);
@@ -544,14 +544,14 @@ filesubstr(char **namptr, int assign)
 	    return 1;
 	} else if (str[1] == Inbrack &&
 		   (dirfunc = getshfunc("zsh_directory_name")) &&
-		   (ptr = strchr(str+2, Outbrack))) {
+		   (ptr2 = strchr(str+2, Outbrack))) {
 	    char **arr;
-	    untokenize(tmp = dupstrpfx(str+2, ptr - (str+2)));
+	    untokenize(tmp = dupstrpfx(str+2, ptr2 - (str+2)));
 	    remnulargs(tmp);
 	    arr = subst_string_by_func(dirfunc, "n", tmp);
 	    res = arr ? *arr : NULL;
 	    if (res) {
-		*namptr = dyncat(res, ptr+1);
+		*namptr = dyncat(res, ptr2+1);
 		return 1;
 	    }
 	    if (isset(NOMATCH))