mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-12-14 20:20:30 +00:00
Prevent use of shell as a hashbang program
This doesn't do what you want (it'll infinite loop), so while special casing it /is/ ugly, it's better than a confusing error. Closes #1386.
This commit is contained in:
parent
7535972a30
commit
e655c6d302
@ -132,6 +132,13 @@ local function executeProgram(remainingRecursion, path, args)
|
|||||||
if not resolvedHashbangProgram then
|
if not resolvedHashbangProgram then
|
||||||
printError("Hashbang program not found: " .. originalHashbangPath)
|
printError("Hashbang program not found: " .. originalHashbangPath)
|
||||||
return false
|
return false
|
||||||
|
elseif resolvedHashbangProgram == "rom/programs/shell.lua" and #hashbangArgs == 0 then
|
||||||
|
-- If we try to launch the shell then our shebang expands to "shell <program>", which just does a
|
||||||
|
-- shell.run("<program>") again, resulting in an infinite loop. This may still happen (if the user
|
||||||
|
-- has a custom shell), but this reduces the risk.
|
||||||
|
-- It's a little ugly special-casing this, but it's probably worth warning about.
|
||||||
|
printError("Cannot use the shell as a hashbang program")
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Add the path and any arguments to the interpreter's arguments
|
-- Add the path and any arguments to the interpreter's arguments
|
||||||
|
@ -21,14 +21,16 @@ describe("The shell", function()
|
|||||||
|
|
||||||
expect(args):same { [0] = "/test-rom/data/dump-args", "arg1", "arg 2" }
|
expect(args):same { [0] = "/test-rom/data/dump-args", "arg1", "arg 2" }
|
||||||
end)
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
|
describe("hashbangs", function()
|
||||||
local function make_hashbang_file(target, filename)
|
local function make_hashbang_file(target, filename)
|
||||||
local tmp = fs.open(filename or "test-files/out.lua", "w")
|
local tmp = fs.open(filename or "test-files/out.lua", "w")
|
||||||
tmp.write("#!" .. target)
|
tmp.write("#!" .. target)
|
||||||
tmp.close()
|
tmp.close()
|
||||||
end
|
end
|
||||||
|
|
||||||
it("supports hashbangs", function()
|
it("has basic support", function()
|
||||||
make_hashbang_file("/test-rom/data/dump-args")
|
make_hashbang_file("/test-rom/data/dump-args")
|
||||||
shell.execute("test-files/out.lua", "arg1", "arg2")
|
shell.execute("test-files/out.lua", "arg1", "arg2")
|
||||||
|
|
||||||
@ -82,6 +84,16 @@ describe("The shell", function()
|
|||||||
make_hashbang_file("test-files/out.lua")
|
make_hashbang_file("test-files/out.lua")
|
||||||
expect(shell.execute("test-files/out.lua")):eq(false)
|
expect(shell.execute("test-files/out.lua")):eq(false)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it("returns error for using the shell", function()
|
||||||
|
make_hashbang_file("shell")
|
||||||
|
expect(shell.execute("test-files/out.lua")):eq(false)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("allows running a shell with arguments", function()
|
||||||
|
make_hashbang_file("shell /test-rom/data/dump-args")
|
||||||
|
expect(shell.execute("test-files/out.lua")):eq(true)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe("shell.run", function()
|
describe("shell.run", function()
|
||||||
|
Loading…
Reference in New Issue
Block a user