Hi,
I had difficulties running the setup and changing values (like username and pass) in the configwizard. It seemed that changing default values was not possible.
Reason:
There are multiple places in configwizard.cpp where strncopy uses sizeof(CONST). In this case too little bytes are copied.
Examples:
strncpy(config.language, server.arg("language").c_str(), sizeof(MAX_LANGUAGE));
strncpy(config.http_username, server.arg("http_username").c_str(), sizeof(MAX_HTTP_USERNAME));
strncpy(config.http_password, server.arg("http_password").c_str(), sizeof(MAX_HTTP_PASSWORD));
strncpy(config.wifi_hostname, server.arg("hostname").c_str(), sizeof(MAX_WIFI_HOSTNAME));
etc...
please use:
strncpy(config.language, server.arg("language").c_str(), MAX_LANGUAGE);
etc..
And all will work fine!
Note also that strncpy will not zero-terminate the string which also might lead to unpredicted results in case one uses a large string. Actually you should zero terminate it by: config.language[MAX_LANGUAGE-1] = '\0'
or create a function:
void safestrcpy(char dst, const char* src, int max_length)
{
strncpy(dst, src, max_length);
dst[max_length-1] = '\0';
}
Hi,
I had difficulties running the setup and changing values (like username and pass) in the configwizard. It seemed that changing default values was not possible.
Reason:
There are multiple places in configwizard.cpp where strncopy uses sizeof(CONST). In this case too little bytes are copied.
Examples:
strncpy(config.language, server.arg("language").c_str(), sizeof(MAX_LANGUAGE));
strncpy(config.http_username, server.arg("http_username").c_str(), sizeof(MAX_HTTP_USERNAME));
strncpy(config.http_password, server.arg("http_password").c_str(), sizeof(MAX_HTTP_PASSWORD));
strncpy(config.wifi_hostname, server.arg("hostname").c_str(), sizeof(MAX_WIFI_HOSTNAME));
etc...
please use:
strncpy(config.language, server.arg("language").c_str(), MAX_LANGUAGE);
etc..
And all will work fine!
Note also that strncpy will not zero-terminate the string which also might lead to unpredicted results in case one uses a large string. Actually you should zero terminate it by: config.language[MAX_LANGUAGE-1] = '\0'
or create a function:
void safestrcpy(char dst, const char* src, int max_length)
{
strncpy(dst, src, max_length);
dst[max_length-1] = '\0';
}