From efa646da494c659d24bc1f09936645eed1a10244 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Thu, 20 Nov 2014 06:17:39 +0100 Subject: renamed ED hook register to "ED" and protect ED hook executions SciTECO commands usually only take parameters from the stack that they need. Without protecting the ED hook execution with brace operators, additional arguments not consumed by the hook-dispatching command are passed into the ED hook invocation. Also an ED hook macro could leave additional values on the expression stack (by accident). All of this may lead to undefined behaviour if ED hooks are involved. --- src/qregisters.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/qregisters.cpp b/src/qregisters.cpp index 223a707..89b2afd 100644 --- a/src/qregisters.cpp +++ b/src/qregisters.cpp @@ -366,11 +366,32 @@ QRegisterStack::~QRegisterStack() void QRegisters::hook(Hook type) { + QRegister *reg; + if (!(Flags::ed & Flags::ED_HOOKS)) return; + reg = globals["ED"]; + if (!reg) + throw Error("Undefined ED-hook register (\"ED\")"); + + /* + * ED-hook execution should not see any + * integer parameters but the hook type. + * Such parameters could confuse the ED macro + * and macro authors do not expect side effects + * of ED macros on the expression stack. + * Also make sure it does not leave behind + * additional arguments on the stack. + * + * So this effectively executes: + * (typeM[ED]^[) + */ + expressions.push(Expressions::OP_BRACE); expressions.push(type); - globals["0"]->execute(); + reg->execute(); + expressions.discard_args(); + expressions.eval(true); } void -- cgit v1.2.3