#175467 zsh -n wrongly executes math expressions

Package:
zsh
Source:
zsh
Description:
shell with lots of features
Submitter:
Date:
2012-12-20 22:33:06 UTC
Severity:
normal
#175467#5
Date:
2003-01-05 18:41:58 UTC
From:
To:
the zsh -n test is inappropriate.  the vux package requires zsh modules,
which aren't loaded with -n.

monkey % lintian -i ../vux_0.3.4_i386.changes
E: vux: shell-script-fails-syntax-check ./usr/bin/vux
N:
N:   Running this shell script with the shell's -n option set fails, which
N:   means that the script has syntax errors.
N:
N:   Run e.g. sh -n yourscript to see the errors yourself.
N:

monkey % zsh -n =vux
/usr/bin/vux:766: unknown function: int
/usr/bin/vux:784: bad math expression: operator expected at `h'

#175467#10
Date:
2003-01-05 19:56:16 UTC
From:
To:
So is zsh -n generally screwed up, or is this a bug in zsh -n?
#175467#15
Date:
2003-01-05 20:05:52 UTC
From:
To:
Well, -n means NO_EXEC, so it would be a bug for zsh -n to execute
module load commands.  On the other hand, those modules need to be
loaded for zsh to know the proper syntax to check.  Quite a dilemma.

Probably the least ugly thing would be to have a
--no-exec --just-kidding-you-can-exec-zmodload-but-nothing-else

Who knows if there are other bizarre ramifications.

#175467#20
Date:
2003-01-05 20:13:12 UTC
From:
To:
If you run zsh -n on a script which uses zsh/mathfunc, zsh will
not exec zmodload, and thus not be aware of new math syntax.

Is an EXEC_ZMODLOAD option in order?

#175467#25
Date:
2003-01-05 22:35:31 UTC
From:
To:
On Jan 5,  3:13pm, Clint Adams wrote:
}
} If you run zsh -n on a script which uses zsh/mathfunc, zsh will
} not exec zmodload, and thus not be aware of new math syntax.

} Is an EXEC_ZMODLOAD option in order?

That solution is not particularly useful.  Consider something of the form

    if test ...
    then zmodload zsh/mathfunc
    fi

If you can't execute the conditional because of -n, how do you know that
it's safe to execute the zmodload?

IMO you've identified a deeper problem, which is that no module should be
allowed to alter the syntax accepted by the parser.  Conversely, if the
parser is able to cope with the syntax in the absence of the module, then
`zsh -n' has no business complaining about the semantics.

In this example:

`zsh -n' should simply accept that `int' IS a function, and should not try
to look it up.

In this case:

I can't give an opinion, "bad math expression" is too generic an error.

#175467#30
Date:
2003-01-06 00:19:42 UTC
From:
To:
I don't appear to have the same version, but I get the same error on
line 788, which is

minimum_age=$(( minimum_age * age_format ))

Looks like there are some if/thens which are not being executed which
would change $minimum_age from "1h" to its equivalent in seconds.

Said version attached for your edification.

#175467#35
Date:
2003-01-06 02:02:40 UTC
From:
To:
On Jan 5,  7:19pm, Clint Adams wrote:
}
} minimum_age=$(( minimum_age * age_format ))
}
} Looks like there are some if/thens which are not being executed which
} would change $minimum_age from "1h" to its equivalent in seconds.

OK, so the problem is that `zsh -n' is executing math expressions.  It
should probably treat math expressions just like any other builtin or
command when the -n option is present; that is, do not execute them.

#175467#46
Date:
2004-03-11 16:31:21 UTC
From:
To:
Index: Src/subst.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/subst.c,v
retrieving revision 1.36
diff -u -r1.36 subst.c
--- Src/subst.c	30 Aug 2003 19:12:18 -0000	1.36
+++ Src/subst.c	11 Mar 2004 16:20:38 -0000
@@ -168,7 +168,11 @@
 	    if (endchar == Outpar && str2[1] == '(' && str[-2] == ')') {
 		/* Math substitution of the form $((...)) */
 		str[-2] = '\0';
-		str = arithsubst(str2 + 2, &str3, str);
+		if (isset(EXECOPT)) {
+		    str = arithsubst(str2 + 2, &str3, str);
+		} else {
+		    strncpy(str3, str2, 1);
+		}
 		setdata(node, (void *) str3);
 		continue;
 	    }

#175467#51
Date:
2004-03-14 16:24:59 UTC
From:
To:
Clint Adams wrote:

I haven't seen the original, but it probably refers to (( ... ))
commands, not $(( ... )) substitutions.  But I can't be sure.

#175467#56
Date:
2004-03-14 18:17:36 UTC
From:
To:
[the thread is 18054, 18055, 18056, 18057, 19601, 19620]

With respect to the syntax errors caused by zsh/mathfunc not being
loaded, it doesn't make sense to substitute $(()) or nor execute
(( )) when NO_EXEC is set.  I don't know about in general.

#175467#63
Date:
2008-12-30 01:54:53 UTC
From:
To:
found 175467 4.3.9

With vux 0.4.9 and zsh 4.3.9, I get:

richih@adamantium 4.3.9-dev-1-cvs1216 ~ % zsh-beta -n =vux
/usr/bin/vux:1251: unknown function: int
/usr/bin/vux:1269: bad math expression: operator expected at `h'
richih@adamantium 4.3.9-dev-1-cvs1216 ~ %