aboutsummaryrefslogtreecommitdiffstats
path: root/klippy
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2024-11-26 14:50:45 -0500
committerKevin O'Connor <kevin@koconnor.net>2024-12-01 13:15:08 -0500
commit5493c603735d52ff1c03c0fa82a405edc30bd14c (patch)
treebd48d4d5ad93020fc87d6d07e8f473e7f340e262 /klippy
parent847331260c84e9de00404aa98f0029184150a897 (diff)
downloadkutter-5493c603735d52ff1c03c0fa82a405edc30bd14c.tar.gz
kutter-5493c603735d52ff1c03c0fa82a405edc30bd14c.tar.xz
kutter-5493c603735d52ff1c03c0fa82a405edc30bd14c.zip
gcode: Validate extended g-code command names
Extended g-code command names may only contain A-Z, 0-9, and underscore, and the first two characters may not be digits. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy')
-rw-r--r--klippy/gcode.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/klippy/gcode.py b/klippy/gcode.py
index 15ab624a..ee2a09d9 100644
--- a/klippy/gcode.py
+++ b/klippy/gcode.py
@@ -133,6 +133,10 @@ class GCodeDispatch:
raise self.printer.config_error(
"gcode command %s already registered" % (cmd,))
if not self.is_traditional_gcode(cmd):
+ if (cmd.upper() != cmd or not cmd.replace('_', 'A').isalnum()
+ or cmd[0].isdigit() or cmd[1:2].isdigit()):
+ raise self.printer.config_error(
+ "Can't register '%s' as it is an invalid name" % (cmd,))
origfunc = func
func = lambda params: origfunc(self._get_extended_params(params))
self.ready_gcode_handlers[cmd] = func