aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/extras/gcode_macro.py
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2021-01-14 22:13:50 -0500
committerKevin O'Connor <kevin@koconnor.net>2021-01-20 16:25:25 -0500
commit023a985bfc8a627b1e4ccff797fbc33e3d064d6c (patch)
tree744d4a41bcd50c4dd4514e7ce27e938cfecd6fce /klippy/extras/gcode_macro.py
parent5b9beb52f6b417beb619c00b6b92ada6aabd32a8 (diff)
downloadkutter-023a985bfc8a627b1e4ccff797fbc33e3d064d6c.tar.gz
kutter-023a985bfc8a627b1e4ccff797fbc33e3d064d6c.tar.xz
kutter-023a985bfc8a627b1e4ccff797fbc33e3d064d6c.zip
gcode_macro: Use deepcopy() on get_status() results
If a get_status() method returns a mutable object (such as a list or dict) then it would be possible for a gcode command template to incorrectly alter the program's internal state. Perform a deepcopy() operation on all get_status() return results to avoid that. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/extras/gcode_macro.py')
-rw-r--r--klippy/extras/gcode_macro.py9
1 files changed, 4 insertions, 5 deletions
diff --git a/klippy/extras/gcode_macro.py b/klippy/extras/gcode_macro.py
index aae5f3bb..3121024e 100644
--- a/klippy/extras/gcode_macro.py
+++ b/klippy/extras/gcode_macro.py
@@ -1,9 +1,9 @@
# Add ability to define custom g-code macros
#
-# Copyright (C) 2018-2019 Kevin O'Connor <kevin@koconnor.net>
+# Copyright (C) 2018-2021 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
-import traceback, logging, ast
+import traceback, logging, ast, copy
import jinja2
@@ -26,7 +26,7 @@ class GetStatusWrapper:
raise KeyError(val)
if self.eventtime is None:
self.eventtime = self.printer.get_reactor().monotonic()
- self.cache[sval] = res = dict(po.get_status(self.eventtime))
+ self.cache[sval] = res = copy.deepcopy(po.get_status(self.eventtime))
return res
def __contains__(self, val):
try:
@@ -157,9 +157,8 @@ class GCodeMacro:
pdesc = "Renamed builtin of '%s'" % (self.alias,)
self.gcode.register_command(self.rename_existing, prev_cmd, desc=pdesc)
self.gcode.register_command(self.alias, self.cmd, desc=self.cmd_desc)
- return dict(self.variables)
def get_status(self, eventtime):
- return dict(self.variables)
+ return self.variables
cmd_SET_GCODE_VARIABLE_help = "Set the value of a G-Code macro variable"
def cmd_SET_GCODE_VARIABLE(self, gcmd):
variable = gcmd.get('VARIABLE')