[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Possible bug in getfunc() in lbaselib.c (5.1.1)?
- From: roberto@... (Roberto Ierusalimschy)
- Date: Fri, 9 Feb 2007 10:03:39 -0200
> I don't know if it will break other things, but this patch works for me
> to correct the problem noted above:
>
> --- lua-5.1.1.orig/src/lbaselib.c 2006-06-02 11:34:00.000000000 -0400
> +++ lua-5.1.1/src/lbaselib.c 2007-02-08 17:40:31.000000000 -0500
> @@ -118,7 +118,10 @@
> if (lua_isfunction(L, 1)) lua_pushvalue(L, 1);
> else {
> lua_Debug ar;
> - int level = luaL_optint(L, 1, 1);
> + int type = lua_type(L, 1);
> + int level;
> + luaL_argcheck(L, type == LUA_TNUMBER, 1, "must be function or number");
> + level = lua_tonumber(L, 1);
> luaL_argcheck(L, level >= 0, 1, "level must be non-negative");
> if (lua_getstack(L, level, &ar) == 0)
> luaL_argerror(L, 1, "invalid level");
I am afraid this patch would disallow the call "getfenv()".
> A better solution to the general problem would be to propagate the error
> from loadfile(), but I still think this is a bug in setfenv().
Yes (using "assert") and yes.
-- Roberto