summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBart Schaefer <barts@users.sourceforge.net>2005-09-24 17:43:55 +0000
committerBart Schaefer <barts@users.sourceforge.net>2005-09-24 17:43:55 +0000
commit8d6cd1dc94f985e98a794d7e8d9f23ebe0b6d7e6 (patch)
tree735af557068536b58823ce9a909373bfb6dac55d
parentad2bd42c858aa7236e7b7404806d16b5b0efb6ac (diff)
downloadzsh-8d6cd1dc94f985e98a794d7e8d9f23ebe0b6d7e6.tar.gz
zsh-8d6cd1dc94f985e98a794d7e8d9f23ebe0b6d7e6.zip
unposted: range-checking of numeric arguments in zargs
-rw-r--r--ChangeLog5
-rw-r--r--Functions/Misc/zargs33
2 files changed, 35 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index d4ce2f9d2..db7909dd9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2005-09-24 Bart Schaefer <schaefer@brasslantern.com>
+
+ * unposted: Functions/Misc/zargs: add range-checking of numeric
+ options.
+
2005-09-23 Peter Stephenson <pws@csr.com>
* 21758: Doc/Zsh/expn.yo, Src/exec.c: optimise =(<<<...) to
diff --git a/Functions/Misc/zargs b/Functions/Misc/zargs
index 71360e4ca..58d84617e 100644
--- a/Functions/Misc/zargs
+++ b/Functions/Misc/zargs
@@ -31,6 +31,12 @@
#
# BUGS:
#
+# In the interests of expediency, numeric options (max-procs, max-lines,
+# etc.) are range-checked only when their values make a difference to the
+# end result. Because of the way zsh handles variables in math context,
+# it's possible to pass the name of a variable as the value of a numeric
+# option, and the value of that variable becomes the value of the option.
+#
# "Killed by a signal" is determined by the usual shell rule that $? is
# the signal number plus 128, so zargs can be fooled by a command that
# explicitly exits with 129+. Also, zsh prior to 4.1.x returns 1 rather
@@ -207,6 +213,11 @@ then
fi
n=${${n##-(n|-max-args(=|))}:-$[ARGC+c]}
+if (( n <= 0 ))
+then
+ print -u2 'zargs: value for max-args must be >= 1'
+ return 1
+fi
if (( n > c ))
then (( n -= c ))
@@ -215,7 +226,26 @@ else
return 1
fi
+s=${${s##-(s|-max-chars(=|))}:-20480}
+if (( s <= 0 ))
+then
+ print -u2 'zargs: value for max-chars must be >= 1'
+ return 1
+fi
+
+l=${${${l##*-(l|L|-max-lines(=|))}[-1]}:-${${l[1]:+1}:-$ARGC}}
+if (( l <= 0 ))
+then
+ print -u2 'zargs: value for max-lines must be >= 1'
+ return 1
+fi
+
P=${${P##-(P|-max-procs(=|))}:-1}
+if (( P < 0 ))
+then
+ print -u2 'zargs: value for max-procs must be >= 0'
+ return 1
+fi
if (( P != 1 && ARGC > 1 ))
then
@@ -230,9 +260,6 @@ then
fi
fi
-s=${${s##-(s|-max-chars(=|))}:-20480}
-l=${${${l##*-(l|L|-max-lines(=|))}[-1]}:-${${l[1]:+1}:-$ARGC}}
-
# Everything has to be in a subshell just in case of backgrounding jobs,
# so that we don't unintentionally "wait" for jobs of the parent shell.
(