From 6dc6ea419e8b467e00c3777a3dcf6ba4d9a4d511 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Mart=C3=ADnez?= Date: Thu, 4 Feb 2016 09:58:44 -0300 Subject: [PATCH] builtin: Fix `print` crashing on nil "holes". The engine implementation of `print` packs the varargs into a table and passes the table directly to `table.concat`. If you pass any value not supported by `table.concat` (particularly `nil`), the server crashes. This is unexpected behavior, as `print` is supposed to be able to work with anything. This patch changes the implementation so it first converts all arguments using `tostring`, which fixes the issue and makes the custom `print` function compatible with the stock Lua behavior. --- builtin/init.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/builtin/init.lua b/builtin/init.lua index b300446..6b27cf7 100644 --- a/builtin/init.lua +++ b/builtin/init.lua @@ -12,7 +12,11 @@ if core.print then -- Override native print and use -- terminal if that's turned on function print(...) - core_print(table.concat({...}, "\t")) + local n, t = select("#", ...), { ... } + for i = 1, n do + t[i] = tostring(t[i]) + end + core_print(table.concat(t, "\t")) end core.print = nil -- don't pollute our namespace end