Skip to content

Commit

Permalink
Remove string metatable protection
Browse files Browse the repository at this point in the history
The string metatable and environment are no longer shared, so this
sandboxing is no longer required.
  • Loading branch information
SquidDev committed May 7, 2017
1 parent ab9b00a commit 0f2c1d9
Showing 1 changed file with 0 additions and 33 deletions.
33 changes: 0 additions & 33 deletions src/main/resources/assets/computercraft/lua/bios.lua
Original file line number Diff line number Diff line change
Expand Up @@ -132,39 +132,6 @@ if _VERSION == "Lua 5.3" then
]] )()
end

if string.find( _HOST, "ComputerCraft" ) == 1 then
-- Prevent access to metatables or environments of strings, as these are global between all computers
local nativegetmetatable = getmetatable
local nativeerror = error
local nativetype = type
local string_metatable = nativegetmetatable("")
function getmetatable( t )
local mt = nativegetmetatable( t )
if mt == string_metatable then
nativeerror( "Attempt to access string metatable", 2 )
else
return mt
end
end
if _VERSION == "Lua 5.1" and not _CC_DISABLE_LUA51_FEATURES then
local string_env = nativegetfenv(("").gsub)
function getfenv( env )
if env == nil then
env = 2
elseif nativetype( env ) == "number" and env > 0 then
env = env + 1
end
local fenv = nativegetfenv(env)
if fenv == string_env then
--nativeerror( "Attempt to access string metatable", 2 )
return nativegetfenv( 0 )
else
return fenv
end
end
end
end

-- Install lua parts of the os api
function os.version()
return "CraftOS 1.8"
Expand Down

0 comments on commit 0f2c1d9

Please sign in to comment.