Update Network.cpp

This commit is contained in:
Gregg 2023-07-26 20:35:27 -05:00
parent 62f68cb33c
commit 0f6e58435e
1 changed files with 19 additions and 12 deletions

View File

@ -117,9 +117,6 @@ void Network::apConfigure(){
WiFiServer apServer(80);
client=0;
TempBuffer <uint8_t> httpBuf(MAX_HTTP+1);
// uint8_t *httpBuf=tempBuffer.buf;
const byte DNS_PORT = 53;
DNSServer dnsServer;
IPAddress apIP(192, 168, 4, 1);
@ -179,11 +176,21 @@ void Network::apConfigure(){
LOG2(client.remoteIP());
LOG2(" <<<<<<<<<\n");
int nBytes=client.read(httpBuf.get(),MAX_HTTP+1); // read all available bytes up to maximum allowed+1
int messageSize=client.available();
if(nBytes>MAX_HTTP){ // exceeded maximum number of bytes allowed
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 <uint8_t> 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;
}