SuperHouse / esp-open-rtos

Open source FreeRTOS-based ESP8266 software framework
BSD 3-Clause "New" or "Revised" License
1.52k stars 491 forks source link

httpd webserver issue. #592

Open agmuntianu opened 6 years ago

agmuntianu commented 6 years ago

Hi, I have been using the httpd component in esp32 (IDF) , which was ported from this repo, And I have found a heap corruption in it , I no longer use esp8266 , but I would like that someone fixes the issue also here.

In function http_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err), the hs retries counter is being set to 0 after a possible freeing of the 'http_state' structure, this happens on refresh of webpage. So basically hs->retries = 0; needs to be executed before:

        if (err == ERR_CLSD) {
            LWIP_DEBUGF(HTTPD_DEBUG, ("received close connection %p %p\n",pcb,hs));
            http_close_conn(pcb, hs);
        }

BR. Andrei.

flannelhead commented 6 years ago

Thanks for informing! Would you be able provide a patch that fixes the issue?

As a side note: I've been (slowly) working on upstreaming the httpd module to lwIP. The httpd in this repo was taken from lwIP in the first place, and WebSocket support was added but never sent back to lwIP upstream. The httpd module in lwIP has evolved quite a bit after that and probably also this has been fixed there... In the long term it would make sense not to maintain several different ports and forks of the original httpd within the ESP world but rather get the simple changes (Websocket support) upstreamed. My WIP upstreaming work is here and the respective ticket here. If someone wants to help with this, it would ultimately be beneficial for both esp-open-rtos and the IDF.

agmuntianu commented 6 years ago

Hi,

Attached a patch file.

httpd_issue.patch.txt