mirror of
https://github.com/Klipper3d/klipper.git
synced 2025-07-09 07:56:26 -06:00
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>
This commit is contained in:
parent
5b9beb52f6
commit
023a985bfc
4 changed files with 8 additions and 9 deletions
|
@ -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')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue