From 023a985bfc8a627b1e4ccff797fbc33e3d064d6c Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Thu, 14 Jan 2021 22:13:50 -0500 Subject: 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 --- klippy/extras/gcode_macro.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'klippy/extras/gcode_macro.py') 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 +# Copyright (C) 2018-2021 Kevin O'Connor # # 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') -- cgit v1.2.3-70-g09d2