Skip to content

Commit

Permalink
stratum: function to check hex strings validity
Browse files Browse the repository at this point in the history
  • Loading branch information
tpruvot committed Mar 14, 2018
1 parent bd888ff commit 165e93b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions stratum/client_submit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

///////////////////////////////////////////////////////////////////////////////////////////

Expand Down
8 changes: 8 additions & 0 deletions stratum/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 2 additions & 0 deletions stratum/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 165e93b

Please sign in to comment.