@@ -135,10 +135,29 @@ local code_prohibited = function(code)
135
135
end
136
136
end
137
137
138
- local safeprint = function (param )
138
+ local safe_print = function (param )
139
139
print (dump (param ))
140
140
end
141
141
142
+ deep_copy = function (original ) -- deep copy that removes functions
143
+ if type (original ) == ' table' then -- nested table
144
+ local copy = {}
145
+ for key , value in next , original , nil do
146
+ copy [deep_copy (key )] = deep_copy (value )
147
+ end
148
+ setmetatable (copy , deep_copy (getmetatable (original )))
149
+ return copy
150
+ elseif type (original ) == ' function' then -- ignore functions
151
+ return nil
152
+ else -- by-value type
153
+ return original
154
+ end
155
+ end
156
+
157
+ local safe_serialize = function (value )
158
+ return minetest .serialize (deep_copy (value ))
159
+ end
160
+
142
161
local interrupt = function (params )
143
162
lc_update (params .pos , {type = " interrupt" , iid = params .iid })
144
163
end
@@ -150,15 +169,16 @@ local getinterrupt = function(pos)
150
169
local meta = minetest .env :get_meta (pos )
151
170
local interrupts = minetest .deserialize (meta :get_string (" lc_interrupts" )) or {}
152
171
local found = false
172
+ local search = safe_serialize (iid )
153
173
for _ , i in ipairs (interrupts ) do
154
- if minetest . serialize (i ) == minetest . serialize ( iid ) then
174
+ if safe_serialize (i ) == search then
155
175
found = true
156
176
break
157
177
end
158
178
end
159
179
if not found then
160
180
table.insert (interrupts , iid )
161
- meta :set_string (" lc_interrupts" , minetest . serialize (interrupts ))
181
+ meta :set_string (" lc_interrupts" , safe_serialize (interrupts ))
162
182
end
163
183
minetest .after (time , interrupt , {pos = pos , iid = iid })
164
184
end
@@ -181,7 +201,7 @@ local create_environment = function(pos, mem, event)
181
201
local rports = get_real_portstates (pos )
182
202
183
203
return {
184
- print = safeprint ,
204
+ print = safe_print ,
185
205
pin = merge_portstates (vports , rports ),
186
206
port = vports ,
187
207
interrupt = getinterrupt (pos ),
@@ -272,15 +292,16 @@ local load_memory = function(meta)
272
292
end
273
293
274
294
local save_memory = function (meta , mem )
275
- meta :set_string (" lc_memory" , minetest . serialize (mem ))
295
+ meta :set_string (" lc_memory" , safe_serialize (mem ))
276
296
end
277
297
278
298
local interrupt_allow = function (meta , event )
279
299
if event .type ~= " interrupt" then return true end
280
300
281
301
local interrupts = minetest .deserialize (meta :get_string (" lc_interrupts" )) or {}
302
+ local search = safe_serialize (event .iid )
282
303
for _ , i in ipairs (interrupts ) do
283
- if minetest . serialize (i ) == minetest . serialize ( event . iid ) then
304
+ if safe_serialize (i ) == search then
284
305
return true
285
306
end
286
307
end
0 commit comments