BitMaker-hub / NerdMiner_v2

Improved version of first ESP32 NerdMiner
Other
1.37k stars 249 forks source link

Username is too short, only 80 characters #352

Open PSLLSP opened 3 months ago

PSLLSP commented 3 months ago

NerdMiner 1.6.3

Buffer allocated for pool username is about 80 characters, that is enough when mining BTC at most solo miner pools but could not be enough for some exotic configuration, like mining NANO at UnMineable pool. NANO address is long, it has 65 characters and there are other information passed in username (coin, worker, referral code), and such username is longer than 80 characters; in the real, only 79 characters are allowed, the last byte has to be \0.

Could be length of variable holding username extended, to 128 or even 256 characters? That should not be a problem, ESP32 has a lot of RAM... Similar applies to password field that could be used to send optional parameters to configure mining pool.


Current variable length is defined as 80 and 20, file NerdMiner_v2/src/stratum.h:

typedef struct {
    String sub_details;
    String extranonce1;
    String extranonce2;
    int extranonce2_size;
    char wName[80];
    char wPass[20];
} mining_subscribe;

File NerdMiner_v2/src/drivers/storage/storage.h:

struct TSettings
{
        String WifiSSID{ DEFAULT_SSID };
        String WifiPW{ DEFAULT_WIFIPW };
        String PoolAddress{ DEFAULT_POOLURL };
        char BtcWallet[80]{ DEFAULT_WALLETID };
        char PoolPassword[80]{ DEFAULT_POOLPASS };
        int PoolPort{ DEFAULT_POOLPORT };
        int Timezone{ DEFAULT_TIMEZONE };
        bool saveStats{ DEFAULT_SAVESTATS };
};

File NerdMiner_v2/src/wManager.cpp:

  // Text box (String) - 80 characters maximum
  WiFiManagerParameter addr_text_box("btcAddress", "Your BTC address", Settings.BtcWallet, 80);
...
  // Text box (String) - 80 characters maximum
  WiFiManagerParameter password_text_box("Poolpassword", "Pool password - Optional", Settings.PoolPassword, 80);

UPDATE

There is a bug in the code v1.6.3. When pool username is longer than 80 characters, then it is trimmed to 80 characters AND it is joined with pool password; somewhere test for buffer length is missing and \0 is not added after the username => buffer overflow... Correct behavior should be that username is trimmed to 79 characters and the last byte in the buffer should be \0...