From c9798ba2e9170afeb6781de487a8779235cef82d Mon Sep 17 00:00:00 2001 From: SChernykh Date: Sun, 13 Oct 2019 22:13:29 +0200 Subject: [PATCH] Sync with latest RandomX code Fix a possible out-of-bounds access in superscalar generator --- src/crypto/randomx/superscalar.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/crypto/randomx/superscalar.cpp b/src/crypto/randomx/superscalar.cpp index aaa91f62..7586c028 100644 --- a/src/crypto/randomx/superscalar.cpp +++ b/src/crypto/randomx/superscalar.cpp @@ -631,7 +631,7 @@ namespace randomx { int cycle1 = scheduleUop(mop.getUop1(), portBusy, cycle); int cycle2 = scheduleUop(mop.getUop2(), portBusy, cycle); - if (cycle1 == cycle2) { + if (cycle1 >= 0 && cycle1 == cycle2) { if (commit) { scheduleUop(mop.getUop1(), portBusy, cycle1); scheduleUop(mop.getUop2(), portBusy, cycle2); @@ -755,6 +755,12 @@ namespace randomx { //recalculate when the instruction can be scheduled for execution based on operand availability scheduleCycle = scheduleMop(mop, portBusy, scheduleCycle, scheduleCycle); + if (scheduleCycle < 0) { + if (trace) std::cout << "Unable to map operation '" << mop.getName() << "' to execution port (cycle " << scheduleCycle << ")" << std::endl; + portsSaturated = true; + break; + } + //calculate when the result will be ready depCycle = scheduleCycle + mop.getLatency();