diff --git a/src/datum_protocol.c b/src/datum_protocol.c index 1d636f56..d3139481 100644 --- a/src/datum_protocol.c +++ b/src/datum_protocol.c @@ -1326,15 +1326,22 @@ int datum_protocol_pow(void *arg) { char * const username = (char *)&msg[i]; if (((!datum_config.datum_pool_pass_full_users) && (!datum_config.datum_pool_pass_workers)) || pow->username[0] == '\0') { - i+=snprintf(username, 385, "%s", datum_config.mining_pool_address); + j = snprintf(username, DATUM_PROTOCOL_MAX_USERNAME_LEN + 1, "%s", datum_config.mining_pool_address); } else if (datum_config.datum_pool_pass_full_users && pow->username[0] != '.') { // TODO: Make sure the usernames are addresses, and if not use one of the configured addresses - i+=snprintf(username, 385, "%s", pow->username); - } else if (datum_config.datum_pool_pass_full_users || datum_config.datum_pool_pass_workers) { + j = snprintf(username, DATUM_PROTOCOL_MAX_USERNAME_LEN + 1, "%s", pow->username); + } else { // append the miner's username to the configured address as .workername - i+=snprintf(username, 385, "%s%s%s", datum_config.mining_pool_address, (pow->username[0] == '.') ? "" : ".", pow->username); + j = snprintf(username, DATUM_PROTOCOL_MAX_USERNAME_LEN + 1, "%s%s%s", datum_config.mining_pool_address, (pow->username[0] == '.') ? "" : ".", pow->username); + } + if (j < 0) { + DLOG_ERROR("Unexpected error copying username to POW!"); + // Still submit it without a username in case it's a block + username[0] = '\0'; + j = 0; } - i++; // already 0 from snprintf + if (j > DATUM_PROTOCOL_MAX_USERNAME_LEN) j = DATUM_PROTOCOL_MAX_USERNAME_LEN; + i += j + 1; // including final null byte // reserve 4 bytes for future use memset(&msg[i], 0, 4); i+=4; diff --git a/src/datum_protocol.h b/src/datum_protocol.h index 4782ebb1..a8e2f013 100644 --- a/src/datum_protocol.h +++ b/src/datum_protocol.h @@ -50,6 +50,7 @@ #define DATUM_PROTOCOL_MAX_CMD_DATA_SIZE 4194304 // 2^22 - protocol limit! #define DATUM_PROTOCOL_BUFFER_SIZE (DATUM_PROTOCOL_MAX_CMD_DATA_SIZE*3) +#define DATUM_PROTOCOL_MAX_USERNAME_LEN 384 #define MAX_DATUM_CLIENT_EVENTS 32