Fix issue with buffer overflow for too large screen updated too fast

pull/30/head
Ondřej Hruška 8 years ago
parent e62c4ece90
commit 16f81cd411
  1. 2
      Makefile
  2. 2
      libesphttpd
  3. 19
      user/cgi_sockets.c

@ -65,7 +65,7 @@ LIBS += esphttpd
# compiler flags using during compilation of source files
CFLAGS = -Os -ggdb -std=gnu99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno-inline-functions \
-nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH \
-Wno-address -Wno-unused
-Wno-address -Wno-unused -DHTTPD_MAX_BACKLOG_SIZE=8192
# linker flags used to generate the main object file
LDFLAGS = -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static

@ -1 +1 @@
Subproject commit fba7cec0b6443c5ee71afde9a45cf832c49562c9
Subproject commit a4e0fed2b281760349ddd107b827d8f6b0f56e02

@ -6,28 +6,26 @@
#include "uart_driver.h"
#include "screen.h"
static volatile bool timer_running = false;
static ETSTimer notifyTim;
#define SOCK_BUF_LEN 2048
static char sock_buff[SOCK_BUF_LEN];
static void notifyTimCb(void *arg) {
timer_running = false;
void *data = NULL;
const int bufsiz = 1024;
char buff[bufsiz];
for (int i = 0; i < 20; i++) {
httpd_cgi_state cont = screenSerializeToBuffer(buff, bufsiz, &data);
httpd_cgi_state cont = screenSerializeToBuffer(sock_buff, SOCK_BUF_LEN, &data);
int flg = 0;
if (cont == HTTPD_CGI_MORE) flg |= WEBSOCK_FLAG_MORE;
if (i > 0) flg |= WEBSOCK_FLAG_CONT;
cgiWebsockBroadcast(URL_WS_UPDATE, buff, (int) strlen(buff), flg);
cgiWebsockBroadcast(URL_WS_UPDATE, sock_buff, (int) strlen(sock_buff), flg);
if (cont == HTTPD_CGI_DONE) break;
}
screenSerializeToBuffer(NULL, bufsiz, &data);
screenSerializeToBuffer(NULL, SOCK_BUF_LEN, &data);
}
static ETSTimer notifyTim;
/**
* Broadcast screen state to sockets.
* This is a callback for the Screen module,
@ -35,9 +33,6 @@ static void notifyTimCb(void *arg) {
*/
void ICACHE_FLASH_ATTR screen_notifyChange(void)
{
if (timer_running) return;
timer_running = true;
os_timer_disarm(&notifyTim);
os_timer_setfn(&notifyTim, notifyTimCb, NULL);
os_timer_arm(&notifyTim, 20, 0);

Loading…
Cancel
Save