diff --git a/src/Network.cpp b/src/Network.cpp index 4676fb0..32daa67 100644 --- a/src/Network.cpp +++ b/src/Network.cpp @@ -116,10 +116,7 @@ void Network::apConfigure(){ WiFiServer apServer(80); client=0; - - TempBuffer httpBuf(MAX_HTTP+1); -// uint8_t *httpBuf=tempBuffer.buf; - + const byte DNS_PORT = 53; DNSServer dnsServer; IPAddress apIP(192, 168, 4, 1); @@ -178,17 +175,27 @@ void Network::apConfigure(){ LOG2("<<<<<<<<< "); LOG2(client.remoteIP()); LOG2(" <<<<<<<<<\n"); - - int nBytes=client.read(httpBuf.get(),MAX_HTTP+1); // read all available bytes up to maximum allowed+1 - - if(nBytes>MAX_HTTP){ // exceeded maximum number of bytes allowed + + int messageSize=client.available(); + + if(messageSize>MAX_HTTP){ // exceeded maximum number of bytes allowed badRequestError(); - LOG0("\n*** ERROR: Exceeded maximum HTTP message length\n\n"); + LOG0("\n*** ERROR: HTTP message of %d bytes exceeds maximum allowed (%d)\n\n",messageSize,MAX_HTTP); + continue; + } + + TempBuffer httpBuf(messageSize+1); // leave room for null character added below + + int nBytes=client.read(httpBuf.get(),messageSize); // read all available bytes up to maximum allowed+1 + + if(nBytes!=messageSize || client.available()!=0){ + badRequestError(); + LOG0("\n*** ERROR: HTTP message not read correctly. Expected %d bytes, read %d bytes, %d bytes remaining\n\n",messageSize,nBytes,client.available()); continue; } - - httpBuf.get()[nBytes]='\0'; // add null character to enable string functions - char *body=(char *)httpBuf.get(); // char pointer to start of HTTP Body + + httpBuf.get()[nBytes]='\0'; // add null character to enable string functions + char *body=(char *)httpBuf.get(); // char pointer to start of HTTP Body char *p; // char pointer used for searches if(!(p=strstr((char *)httpBuf.get(),"\r\n\r\n"))){