Added check to ensure HostName is valid

Must be 255 or less alphanumeric characters or a hyphen, except hyphen can't be first or last character.
This commit is contained in:
Gregg 2021-02-18 21:02:41 -06:00
parent 3bd615bc8b
commit 96d3877ef6
2 changed files with 13 additions and 3 deletions

View File

@ -398,6 +398,16 @@ void Span::checkConnect(){
else else
sprintf(hostName,"%s%s",hostNameBase,hostNameSuffix); sprintf(hostName,"%s%s",hostNameBase,hostNameSuffix);
char d[strlen(hostName)+1];
sscanf(hostName,"%[A-Za-z0-9-]",d);
if(strlen(hostName)>255|| hostName[0]=='-' || hostName[strlen(hostName)-1]=='-' || strlen(hostName)!=strlen(d)){
Serial.printf("\n*** Error: Can't start MDNS due to invalid hostname '%s'.\n",hostName);
Serial.print("*** Hostname must consist of 255 or less alphanumeric characters or a hyphen, except that the hyphen cannot be the first or last character.\n");
Serial.print("*** PROGRAM HALTED!\n\n");
while(1);
}
Serial.print("\nStarting MDNS...\n\n"); Serial.print("\nStarting MDNS...\n\n");
Serial.print("HostName: "); Serial.print("HostName: ");
Serial.print(hostName); Serial.print(hostName);

View File

@ -10,15 +10,15 @@ void setup() {
homeSpan.setLogLevel(1); homeSpan.setLogLevel(1);
// homeSpan.setHostNameSuffix(""); homeSpan.setHostNameSuffix("-lamp1");
homeSpan.setPortNum(1201); homeSpan.setPortNum(1201);
// homeSpan.setMaxConnections(6); // homeSpan.setMaxConnections(6);
// homeSpan.setQRID("One1"); // homeSpan.setQRID("One1");
homeSpan.enableOTA(); homeSpan.enableOTA();
homeSpan.setSketchVersion("Test 1.3.0"); homeSpan.setSketchVersion("Test 1.3.1");
homeSpan.setWifiCallback(wifiEstablished); homeSpan.setWifiCallback(wifiEstablished);
homeSpan.begin(Category::Lighting,"HomeSpan Lamp Server","homespanlamp"); homeSpan.begin(Category::Lighting,"HomeSpan Lamp Server","homespan");
new SpanAccessory(); // Begin by creating a new Accessory using SpanAccessory(), which takes no arguments new SpanAccessory(); // Begin by creating a new Accessory using SpanAccessory(), which takes no arguments