From d0f4a676eca1b341c4c23b96681750e32809661d Mon Sep 17 00:00:00 2001 From: gamax92 Date: Mon, 14 Nov 2016 09:20:01 -0700 Subject: [PATCH 1/4] Validate NBT address of FileSystems Validate the address stored in hard disks and floppy disks and generate a new address if it is now longer a UUID. Fixes breaking out of the sandbox and accessing host files with potential writes. This does not fix being able to modify drives using a debug card or creative mode to access other drives. --- .../integration/opencomputers/DriverFileSystem.scala | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/scala/li/cil/oc/integration/opencomputers/DriverFileSystem.scala b/src/main/scala/li/cil/oc/integration/opencomputers/DriverFileSystem.scala index e64d8b280..fd2e1e5e5 100644 --- a/src/main/scala/li/cil/oc/integration/opencomputers/DriverFileSystem.scala +++ b/src/main/scala/li/cil/oc/integration/opencomputers/DriverFileSystem.scala @@ -2,6 +2,7 @@ package li.cil.oc.integration.opencomputers import li.cil.oc import li.cil.oc.Constants +import li.cil.oc.OpenComputers import li.cil.oc.Settings import li.cil.oc.api import li.cil.oc.api.network.EnvironmentHost @@ -17,6 +18,8 @@ import net.minecraft.item.ItemStack import net.minecraft.nbt.NBTTagCompound object DriverFileSystem extends Item { + val UUIDVerifier = """^([0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12})$""".r + override def worksWith(stack: ItemStack) = isOneOf(stack, api.Items.get(Constants.ItemName.HDDTier1), api.Items.get(Constants.ItemName.HDDTier2), @@ -82,7 +85,14 @@ object DriverFileSystem extends Item { private def addressFromTag(tag: NBTTagCompound) = if (tag.hasKey("node") && tag.getCompoundTag("node").hasKey("address")) { - tag.getCompoundTag("node").getString("address") + tag.getCompoundTag("node").getString("address") match { + case UUIDVerifier(address) => address + case _ => // Invalid disk address. + val newAddress = java.util.UUID.randomUUID().toString + tag.getCompoundTag("node").setString("address", newAddress) + OpenComputers.log.warn(s"Generated new address for disk '${newAddress}'.") + newAddress + } } else java.util.UUID.randomUUID().toString From baff8dcca638e481cddd71eaf62117abbfa7a5c9 Mon Sep 17 00:00:00 2001 From: Vexatos Date: Thu, 17 Nov 2016 23:40:51 +0100 Subject: [PATCH 2/4] Fixed RedLogic redstone input reading. --- src/main/scala/li/cil/oc/integration/redlogic/ModRedLogic.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/li/cil/oc/integration/redlogic/ModRedLogic.scala b/src/main/scala/li/cil/oc/integration/redlogic/ModRedLogic.scala index a762a2f5b..a41a0f7b8 100644 --- a/src/main/scala/li/cil/oc/integration/redlogic/ModRedLogic.scala +++ b/src/main/scala/li/cil/oc/integration/redlogic/ModRedLogic.scala @@ -19,7 +19,7 @@ object ModRedLogic extends ModProxy with RedstoneProvider { } override def computeInput(pos: BlockPosition, side: ForgeDirection): Int = { - pos.world.get.getTileEntity(pos) match { + pos.world.get.getTileEntity(pos.offset(side)) match { case emitter: IRedstoneEmitter => var strength = 0 for (i <- -1 to 5) { From 60512f71d56da673cd6a942409f3ec24e312cacb Mon Sep 17 00:00:00 2001 From: gamax92 Date: Tue, 29 Nov 2016 15:36:58 -0700 Subject: [PATCH 3/4] Fix kernel naming in LuaJ LuaC has "=machine" but LuaJ has "=kernel" --- .../li/cil/oc/server/machine/luaj/LuaJLuaArchitecture.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/li/cil/oc/server/machine/luaj/LuaJLuaArchitecture.scala b/src/main/scala/li/cil/oc/server/machine/luaj/LuaJLuaArchitecture.scala index 024c2fc40..254bf503b 100644 --- a/src/main/scala/li/cil/oc/server/machine/luaj/LuaJLuaArchitecture.scala +++ b/src/main/scala/li/cil/oc/server/machine/luaj/LuaJLuaArchitecture.scala @@ -232,7 +232,7 @@ class LuaJLuaArchitecture(val machine: api.machine.Machine) extends Architecture recomputeMemory(machine.host.internalComponents) - val kernel = lua.load(classOf[Machine].getResourceAsStream(Settings.scriptPath + "machine.lua"), "=kernel", "t", lua) + val kernel = lua.load(classOf[Machine].getResourceAsStream(Settings.scriptPath + "machine.lua"), "=machine", "t", lua) thread = new LuaThread(lua, kernel) // Left as the first value on the stack. true From f48dfee32d57f7d4a9703fb944c397efd9fe7c7a Mon Sep 17 00:00:00 2001 From: Vexatos Date: Sat, 10 Dec 2016 16:10:37 +0100 Subject: [PATCH 4/4] Fix #2173. --- src/main/scala/li/cil/oc/server/machine/Machine.scala | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/scala/li/cil/oc/server/machine/Machine.scala b/src/main/scala/li/cil/oc/server/machine/Machine.scala index 78360eab5..7bc9fd0ed 100644 --- a/src/main/scala/li/cil/oc/server/machine/Machine.scala +++ b/src/main/scala/li/cil/oc/server/machine/Machine.scala @@ -765,7 +765,11 @@ class Machine(val host: MachineHost) extends prefab.ManagedEnvironment with mach }) override def save(nbt: NBTTagCompound): Unit = Machine.this.synchronized(state.synchronized { - assert(!isExecuting) // Lock on 'this' should guarantee this. + // The lock on 'this' should guarantee that this never happens regularly. + // If something other than regular saving tries to save while we are executing code, + // e.g. SpongeForge saving during robot.move due to block changes being captured, + // just don't save this at all. What could possibly go wrong? + if(isExecuting) return if (SaveHandler.savingForClients) { return @@ -1076,4 +1080,4 @@ object Machine extends MachineAPI { } private val threadPool = ThreadPoolFactory.create("Computer", Settings.get.threads) -} \ No newline at end of file +}