Fixed crash and added error message about seed_hash field.

This commit is contained in:
XMRig 2019-08-05 17:48:12 +07:00
parent 044fbd7e82
commit 3543abcc3c
3 changed files with 14 additions and 3 deletions

View file

@ -335,13 +335,19 @@ bool xmrig::Client::parseJob(const rapidjson::Value &params, int *code)
job.setAlgorithm(algo); job.setAlgorithm(algo);
} }
job.setSeedHash(Json::getString(params, "seed_hash"));
job.setHeight(Json::getUint64(params, "height")); job.setHeight(Json::getUint64(params, "height"));
if (!verifyAlgorithm(job.algorithm(), algo)) { if (!verifyAlgorithm(job.algorithm(), algo)) {
*code = 6; *code = 6;
return false;
}
close(); if (job.algorithm().family() == Algorithm::RANDOM_X && !job.setSeedHash(Json::getString(params, "seed_hash"))) {
if (!isQuiet()) {
LOG_ERR("[%s] failed to parse field \"seed_hash\" required by RandomX", url(), algo);
}
*code = 7;
return false; return false;
} }
@ -693,6 +699,9 @@ void xmrig::Client::parseNotification(const char *method, const rapidjson::Value
if (parseJob(params, &code)) { if (parseJob(params, &code)) {
m_listener->onJobReceived(this, m_job, params); m_listener->onJobReceived(this, m_job, params);
} }
else {
close();
}
return; return;
} }

View file

@ -77,5 +77,5 @@ bool xmrig::RxCache::init(const uint8_t *seed)
bool xmrig::RxCache::isReady(const uint8_t *seed) const bool xmrig::RxCache::isReady(const uint8_t *seed) const
{ {
return memcmp(m_seed, seed, sizeof(m_seed)) == 0; return m_initCount && memcmp(m_seed, seed, sizeof(m_seed)) == 0;
} }

View file

@ -51,6 +51,7 @@ public:
inline bool isJIT() const { return m_flags & 8; } inline bool isJIT() const { return m_flags & 8; }
inline const uint8_t *seed() const { return m_seed; } inline const uint8_t *seed() const { return m_seed; }
inline randomx_cache *get() const { return m_cache; } inline randomx_cache *get() const { return m_cache; }
inline uint64_t initCount() const { return m_initCount; }
bool init(const uint8_t *seed); bool init(const uint8_t *seed);
@ -61,6 +62,7 @@ private:
int m_flags = 0; int m_flags = 0;
randomx_cache *m_cache = nullptr; randomx_cache *m_cache = nullptr;
uint64_t m_initCount = 0;
uint8_t m_seed[32]; uint8_t m_seed[32];
}; };