From 2039e10848db3f133fea8a34413166312f277aa8 Mon Sep 17 00:00:00 2001 From: CryptoManiac Date: Sat, 29 Aug 2015 19:46:46 +0300 Subject: [PATCH] ScriptCode: fix stack depth precondition and add preproccessor directive checking to prevent such issues in the future. --- Novacoin/Novacoin.csproj | 2 +- Novacoin/ScriptCode.cs | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Novacoin/Novacoin.csproj b/Novacoin/Novacoin.csproj index 2348e63..825a890 100644 --- a/Novacoin/Novacoin.csproj +++ b/Novacoin/Novacoin.csproj @@ -15,7 +15,7 @@ full false bin\Debug - DEBUG; + DEBUG;CODE_ANALYSIS; prompt 4 false diff --git a/Novacoin/ScriptCode.cs b/Novacoin/ScriptCode.cs index 458445a..1b6cbea 100644 --- a/Novacoin/ScriptCode.cs +++ b/Novacoin/ScriptCode.cs @@ -794,8 +794,8 @@ namespace Novacoin /// Byte sequence private static byte[] stacktop(ref List stack, int nDepth) { - Contract.Requires(nDepth < 0, "Positive stack depth makes no sense."); - Contract.Requires(stack.Count + nDepth > 0, "Value exceeds real stack depth."); + Contract.Requires(nDepth < 0, "Positive or zero stack depth makes no sense."); + Contract.Requires(stack.Count + nDepth >= 0, "Value exceeds real stack depth."); return stack[stack.Count + nDepth]; } @@ -866,8 +866,10 @@ namespace Novacoin var CodeQueue = script.GetByteQueue(); var altStack = new List(); +#if !DEBUG try { +#endif instruction opcode; byte[] pushArg; @@ -1703,12 +1705,14 @@ namespace Novacoin return false; } } +#if !DEBUG } catch (Exception) { // If there are any exceptions then just return false. return false; } +#endif if (vfExec.Count() != 0) { -- 1.7.1