Skip to content

Commit d613935

Browse files
committed
protocol: Define and use DATUM_PROTOCOL_MAX_USERNAME_LEN
1 parent bb9b25a commit d613935

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

src/datum_protocol.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,21 +1326,21 @@ int datum_protocol_pow(void *arg) {
13261326

13271327
char * const username = (char *)&msg[i];
13281328
if (((!datum_config.datum_pool_pass_full_users) && (!datum_config.datum_pool_pass_workers)) || pow->username[0] == '\0') {
1329-
j = snprintf(username, 385, "%s", datum_config.mining_pool_address);
1329+
j = snprintf(username, DATUM_PROTOCOL_MAX_USERNAME_LEN + 1, "%s", datum_config.mining_pool_address);
13301330
} else if (datum_config.datum_pool_pass_full_users && pow->username[0] != '.') {
13311331
// TODO: Make sure the usernames are addresses, and if not use one of the configured addresses
1332-
j = snprintf(username, 385, "%s", pow->username);
1332+
j = snprintf(username, DATUM_PROTOCOL_MAX_USERNAME_LEN + 1, "%s", pow->username);
13331333
} else {
13341334
// append the miner's username to the configured address as .workername
1335-
j = snprintf(username, 385, "%s%s%s", datum_config.mining_pool_address, (pow->username[0] == '.') ? "" : ".", pow->username);
1335+
j = snprintf(username, DATUM_PROTOCOL_MAX_USERNAME_LEN + 1, "%s%s%s", datum_config.mining_pool_address, (pow->username[0] == '.') ? "" : ".", pow->username);
13361336
}
13371337
if (j < 0) {
13381338
DLOG_ERROR("Unexpected error copying username to POW!");
13391339
// Still submit it without a username in case it's a block
13401340
username[0] = '\0';
13411341
j = 0;
13421342
}
1343-
if (j > 384) j = 384;
1343+
if (j > DATUM_PROTOCOL_MAX_USERNAME_LEN) j = DATUM_PROTOCOL_MAX_USERNAME_LEN;
13441344
i += j + 1; // including final null byte
13451345

13461346
// reserve 4 bytes for future use

src/datum_protocol.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050

5151
#define DATUM_PROTOCOL_MAX_CMD_DATA_SIZE 4194304 // 2^22 - protocol limit!
5252
#define DATUM_PROTOCOL_BUFFER_SIZE (DATUM_PROTOCOL_MAX_CMD_DATA_SIZE*3)
53+
#define DATUM_PROTOCOL_MAX_USERNAME_LEN 384
5354

5455
#define MAX_DATUM_CLIENT_EVENTS 32
5556

0 commit comments

Comments
 (0)