From 81722cc7cd717f775eb73250616a3567c8eca940 Mon Sep 17 00:00:00 2001 From: payonel Date: Thu, 23 Nov 2017 22:47:08 -0800 Subject: [PATCH] change FIleSystem.checkHandle() to also check for a table parameter thanks to @Pwootage, who explained this change as such: Previously, checkHandle was not "language safe" (or at least, not JSON-safe): open() returns a HandleValue (which is a type not exposed by the oc-api jar) checkHandle() checks for either a integer, or a HandleValue object When calling through a custom architecture, HandleValue may or may not be preserved, as the underlying language, unless it can attach the original Java object, may not be able to represent the HandleValue class, and so convert it to a table, which checkHandle() did not check for. --- src/main/scala/li/cil/oc/server/component/FileSystem.scala | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/scala/li/cil/oc/server/component/FileSystem.scala b/src/main/scala/li/cil/oc/server/component/FileSystem.scala index 2ff739cb4..5e08d9595 100644 --- a/src/main/scala/li/cil/oc/server/component/FileSystem.scala +++ b/src/main/scala/li/cil/oc/server/component/FileSystem.scala @@ -245,6 +245,11 @@ class FileSystem(val fileSystem: IFileSystem, var label: Label, val host: Option def checkHandle(args: Arguments, index: Int) = { if (args.isInteger(index)) { args.checkInteger(index) + } else if (args.isTable(index)) { + args.checkTable(index).get("handle") match { + case handle: Number => handle.intValue() + case _ => throw new IOException("bad file descriptor") + } } else args.checkAny(index) match { case handle: HandleValue => handle.handle case _ => throw new IOException("bad file descriptor")