diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp --- a/src/script/interpreter.cpp +++ b/src/script/interpreter.cpp @@ -930,6 +930,12 @@ // Disabled opcode. return set_error(serror, SCRIPT_ERR_DISABLED_OPCODE); } + // 2nd operand must not be 0 + if (bn2 == 0) { + return set_error(serror, + SCRIPT_ERR_DIV_BY_ZERO); + } + bn = bn1 / bn2; break; case OP_MOD: diff --git a/src/script/script.h b/src/script/script.h --- a/src/script/script.h +++ b/src/script/script.h @@ -275,6 +275,12 @@ inline CScriptNum operator-(const CScriptNum &rhs) const { return operator-(rhs.m_value); } + inline CScriptNum operator/(const int64_t &rhs) const { + return CScriptNum(m_value / rhs); + } + inline CScriptNum operator/(const CScriptNum &rhs) const { + return operator/(rhs.m_value); + } inline CScriptNum &operator+=(const CScriptNum &rhs) { return operator+=(rhs.m_value);