stratum: function to check hex strings validity

This commit is contained in:
Tanguy Pruvot 2018-03-14 18:12:55 +01:00
parent bd888ff4e2
commit 165e93bf29
3 changed files with 15 additions and 0 deletions

View file

@ -463,6 +463,11 @@ bool client_submit(YAAMP_CLIENT *client, json_value *json_params)
return true;
}
}
else if(!ishexa(extranonce2, client->extranonce2size*2)) {
client_submit_error(client, job, 27, "Invalid nonce2", extranonce2, ntime, nonce);
client->submit_bad++;
return true;
}
///////////////////////////////////////////////////////////////////////////////////////////

View file

@ -417,6 +417,14 @@ void hexlify(char *hex, const unsigned char *bin, int len)
sprintf(hex+strlen(hex), "%02x", bin[i]);
}
bool ishexa(char *hex, int len)
{
for(int i=0; i<len; i++) {
if (!isxdigit(hex[i])) return false;
}
return true;
}
unsigned char binvalue(const char v)
{
if(v >= '0' && v <= '9')

View file

@ -86,6 +86,8 @@ void ser_string_be2(const char *input, char *output, int len);
void string_be(const char *input, char *output);
void string_be1(char *s);
bool ishexa(char *hex, int len);
void hexlify(char *hex, const unsigned char *bin, int len);
void binlify(unsigned char *bin, const char *hex);