aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2014-11-20 06:17:39 +0100
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2014-11-20 06:17:39 +0100
commitefa646da494c659d24bc1f09936645eed1a10244 (patch)
tree3c85985b5c91630224a909fc40cf2e6996a3c645 /src
parentb0bc20bdeae770de3726f87d8ea13038491b2e29 (diff)
downloadsciteco-efa646da494c659d24bc1f09936645eed1a10244.tar.gz
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.
Diffstat (limited to 'src')
-rw-r--r--src/qregisters.cpp23
1 files changed, 22 insertions, 1 deletions
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