summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2006-05-24 11:16:39 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2006-05-24 11:16:39 -0300
commit20f4bbdc3a39446345e5f6433c7c71de60f8a0b7 (patch)
treec89f5df27adca6d82254833eb52a56d49c1ca14e
parentc408158047c24879887379d2f0cec71fd30604cb (diff)
downloadlua-github-20f4bbdc3a39446345e5f6433c7c71de60f8a0b7.tar.gz
does not accept garbage after options (e.g., -ixxx)
-rw-r--r--lua.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/lua.c b/lua.c
index a6405f6a..8cf83087 100644
--- a/lua.c
+++ b/lua.c
@@ -1,5 +1,5 @@
/*
-** $Id: lua.c,v 1.157 2005/12/29 16:23:32 roberto Exp roberto $
+** $Id: lua.c,v 1.158 2006/04/10 18:27:23 roberto Exp roberto $
** Lua stand-alone interpreter
** See Copyright Notice in lua.h
*/
@@ -252,17 +252,30 @@ static int handle_script (lua_State *L, char **argv, int n) {
}
+/* check that argument has no extra characters at the end */
+#define notail(x) {if ((x)[2] != '\0') return -1;}
+
+
static int collectargs (char **argv, int *pi, int *pv, int *pe) {
int i;
for (i = 1; argv[i] != NULL; i++) {
if (argv[i][0] != '-') /* not an option? */
return i;
switch (argv[i][1]) { /* option */
- case '-': return (argv[i+1] != NULL ? i+1 : 0);
- case '\0': return i;
- case 'i': *pi = 1; /* go through */
- case 'v': *pv = 1; break;
- case 'e': *pe = 1; /* go through */
+ case '-':
+ notail(argv[i]);
+ return (argv[i+1] != NULL ? i+1 : 0);
+ case '\0':
+ return i;
+ case 'i':
+ notail(argv[i]);
+ *pi = 1; /* go through */
+ case 'v':
+ notail(argv[i]);
+ *pv = 1;
+ break;
+ case 'e':
+ *pe = 1; /* go through */
case 'l':
if (argv[i][2] == '\0') {
i++;