This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Sangar's profile picture

[CC1.65] Global string metatable is accessible

Started by Sangar, 03 December 2014 - 08:35 PM
Sangar #1
Posted 03 December 2014 - 09:35 PM
In the latest version of CC the string metatable can be accessed (getmetatable("")), and because LuaJ is the way it is, this is the same table instance for all computers. Meaning instantaneous data transfer / hive mind / shared storage / whatever you may want to call it.

Looking at the bios.lua this seems to be an oversight. There is code there to prevent this exact case, but it is broken (compares a method's env to the metatable).

Steps to reproduce:
  • Place two computers
  • Start lua interpreter on both.
  • Run getmetatable("").test = 123 on the first.
  • Run getmetatable("").test on the second, see 123.
ElvishJerricco #2
Posted 03 December 2014 - 10:23 PM
Nice find. I foresee some very interesting hacks in the meantime while this remains unfixed. Obviously it is recommended that these hacks not be relied on…


getmetatable("").computers = getmetatable("").computers or {}
getmetatable("").computers[os.getComputerID()] = function(f)
	local args = {waitForSomething()}
	f(unpack(args)) -- callback the original computer
end

EDIT: Actually, in the same vein, coroutines can be passed around and one computer can manage other computers' threading. How odd…
Edited on 03 December 2014 - 09:35 PM
SquidDev #3
Posted 04 December 2014 - 06:31 PM
I'm guessing this is here:


local string_metatable = nativegetfenv(("").gsub) -- Not actually the metatable
function getmetatable( t )
    local mt = nativegetmetatable( t )
    if mt == string_metatable then
	    nativeerror( "Attempt to access string metatable", 2 )
    else
	    return mt
    end
end

Does anyone know how long this has been here?
Anavrins #4
Posted 01 February 2015 - 04:58 PM
Bumping this to be fixed in 1.66
There's a way you can brick every computer in a world if not used properly.
SquidDev #5
Posted 01 February 2015 - 05:50 PM
Pretty sure this has been fixed now. Haven't tested it but I'm sure Dan has
dan200 #6
Posted 02 February 2015 - 09:21 PM
Fixed in CC1.66