tmc2130: Check field name validity. (#1697)

This avoids crashing Klipper if user entered invalid field name.

Signed-off-by: Artem Belevich <artemb@gmail.com>
This commit is contained in:
Artem Belevich 2019-06-02 08:41:15 -07:00 committed by KevinOConnor
parent 3910a44cc9
commit 72100bc1f2
4 changed files with 12 additions and 4 deletions

View File

@ -354,7 +354,9 @@ class TMC2130:
'VALUE' not in params):
raise gcode.error("Invalid command format")
field = gcode.get_str('FIELD', params)
reg = self.fields.field_to_register[field]
reg = self.fields.field_to_register.get(field)
if reg is None:
raise gcode.error("Unknown field name '%s'" % field)
value = gcode.get_int('VALUE', params)
self.fields.set_field(field, value)
print_time = self.printer.lookup_object('toolhead').get_last_move_time()

View File

@ -427,7 +427,9 @@ class TMC2208:
'VALUE' not in params):
raise gcode.error("Invalid command format")
field = gcode.get_str('FIELD', params)
reg = self.fields.field_to_register[field]
reg = self.fields.field_to_register.get(field)
if reg is None:
raise gcode.error("Unknown field name '%s'" % field)
value = gcode.get_int('VALUE', params)
self.fields.set_field(field, value)
self.printer.lookup_object('toolhead').wait_moves()

View File

@ -294,7 +294,9 @@ class TMC2660:
'VALUE' not in params):
raise gcode.error("Invalid command format")
field = gcode.get_str('FIELD', params)
reg = self.fields.field_to_register[field]
reg = self.fields.field_to_register.get(field)
if reg is None:
raise gcode.error("Unknown field name '%s'" % field)
value = gcode.get_int('VALUE', params)
self.fields.set_field(field, value)
pt = self.printer.lookup_object('toolhead').get_last_move_time()

View File

@ -428,7 +428,9 @@ class TMC5160:
'VALUE' not in params):
raise gcode.error("Invalid command format")
field = gcode.get_str('FIELD', params)
reg = self.fields.field_to_register[field]
reg = self.fields.field_to_register.get(field)
if reg is None:
raise gcode.error("Unknown field name '%s'" % field)
value = gcode.get_int('VALUE', params)
self.fields.set_field(field, value)
print_time = self.printer.lookup_object('toolhead').get_last_move_time()