# HG changeset patch # User Michiel Broek # Date 1562062223 -7200 # Node ID 756d1a63d12975e7936e268775caed40ab091079 # Parent 38e1c91bfd8888f3c6fc28be7bf576adc26ec2e4 Adjusted more strings for new compiler warnings. There should now be no buffer overflows in the app. Changed the date display on the mainscreen. diff -r 38e1c91bfd88 -r 756d1a63d129 main/automation.c --- a/main/automation.c Tue Jul 02 11:00:27 2019 +0200 +++ b/main/automation.c Tue Jul 02 12:10:23 2019 +0200 @@ -614,7 +614,7 @@ xSemaphoreGive(xSemaphoreDriver); } MashState = Sub_Screen = MASH_WAITTEMP; - snprintf(msg, 63, "{\"main\":\"%d\",\"sub\":\"%d\",\"timer\":\"\"}", Main_Screen, Sub_Screen); + snprintf(msg, 255, "{\"main\":\"%d\",\"sub\":\"%d\",\"timer\":\"\"}", Main_Screen, Sub_Screen); ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); ESP_LOGI(TAG, "Mash step %d type: %s time: %d temp: %4.1f min: %4.1f max: %4.1f", Main_Screen - MAIN_AUTO_MASH_IN, mashTypes[recipe.MashStep[Main_Screen - MAIN_AUTO_MASH_IN].Type], @@ -650,7 +650,7 @@ TFT_print(temp_buf, CENTER, 135); SoundPlay(SOUND_Prompt); MashState = Sub_Screen = MASH_INFUSE; - snprintf(msg, 63, "{\"main\":\"%d\",\"sub\":\"%d\",\"timer\":\"%s\"}", Main_Screen, Sub_Screen, temp_buf); + snprintf(msg, 255, "{\"main\":\"%d\",\"sub\":\"%d\",\"timer\":\"%s\"}", Main_Screen, Sub_Screen, temp_buf); ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { // No heating during the infusion. diff -r 38e1c91bfd88 -r 756d1a63d129 main/buttons.c --- a/main/buttons.c Tue Jul 02 11:00:27 2019 +0200 +++ b/main/buttons.c Tue Jul 02 12:10:23 2019 +0200 @@ -814,7 +814,7 @@ void EditUint16(char *label, uint16_t *val, uint16_t min, uint16_t max) { - char *valstr, errmsg[40]; + char *valstr, errmsg[64]; uint16_t newval; errmsg[0] = '\0'; @@ -839,7 +839,7 @@ void EditFloat(char *label, float *val, float min, float max, int decimals) { - char *valstr, errmsg[40]; + char *valstr, errmsg[672]; float newval; errmsg[0] = '\0'; @@ -864,7 +864,7 @@ void EditDouble(char *label, double *val, double min, double max, int decimals) { - char *valstr, errmsg[40]; + char *valstr, errmsg[672]; double newval; errmsg[0] = '\0'; diff -r 38e1c91bfd88 -r 756d1a63d129 main/files.c --- a/main/files.c Tue Jul 02 11:00:27 2019 +0200 +++ b/main/files.c Tue Jul 02 12:10:23 2019 +0200 @@ -18,7 +18,7 @@ */ void Files_Dir(char *path) { - char filename[256], tmp[42]; + char filename[272], tmp[42]; uint16_t y = 28; DIR *dir; struct dirent *de; diff -r 38e1c91bfd88 -r 756d1a63d129 main/recipes.c --- a/main/recipes.c Tue Jul 02 11:00:27 2019 +0200 +++ b/main/recipes.c Tue Jul 02 12:10:23 2019 +0200 @@ -159,7 +159,8 @@ * But check for whirlpool hops too. */ if (strcmp("NAME", _xml_element[4]) == 0) { - snprintf(_xml_add_name, 63, "%s", char_data_buffer); + _xml_add_name[0] = '\0'; + strncat(_xml_add_name, char_data_buffer, 63); } else if (strcmp("USE", _xml_element[4]) == 0) { _xml_add_valid = (strcmp("Boil", char_data_buffer) == 0); // Only "Boil" is a valid hop if (strcmp("Aroma", char_data_buffer) == 0) { @@ -181,7 +182,8 @@ * Fermentabes that must be added during the boil. */ if (strcmp("NAME", _xml_element[4]) == 0) { - snprintf(_xml_add_name, 63, "%s", char_data_buffer); + _xml_add_name[0] = '\0'; + strncat(_xml_add_name, char_data_buffer, 63); } else if (strcmp("TYPE", _xml_element[4]) == 0) { if ((strcmp("Sugar", char_data_buffer) == 0)/* || (strcmp("Adjunct", char_data_buffer) == 0)*/) { _xml_add_type = ADDITION_FERMENTABLE; @@ -197,7 +199,8 @@ * Check for Misc additions to add during the boil. */ if (strcmp("NAME", _xml_element[4]) == 0) { - snprintf(_xml_add_name, 63, "%s", char_data_buffer); + _xml_add_name[0] = '\0'; + strncat(_xml_add_name, char_data_buffer, 63); } else if (strcmp("USE", _xml_element[4]) == 0) { _xml_add_valid = (strcmp("Boil", char_data_buffer) == 0); // Only "Boil" is a valid hop. } else if (strcmp("TYPE", _xml_element[4]) == 0) { @@ -217,7 +220,8 @@ } else if ((_xml_depth >= 4) && (strcmp("MASH", _xml_element[2]) == 0)) { if ((_xml_depth >= 6) && (strcmp("MASH_STEP", _xml_element[4]) == 0)) { if (strcmp("NAME", _xml_element[5]) == 0) { - snprintf(_xml_add_name, 31, "%s", char_data_buffer); + _xml_add_name[0] = '\0'; + strncat(_xml_add_name, char_data_buffer, 63); } else if (strcmp("TYPE", _xml_element[5]) == 0) { // Temperature Infusion Decoction _xml_add_valid = (strcmp("Temperature", char_data_buffer) == 0); @@ -293,7 +297,8 @@ } if ((_xml_depth == 5) && (strcmp("MASH_STEP", _xml_element[4]) == 0)) { _xml_mashsteps++; - sprintf(recipe.MashStep[_xml_mashsteps].Name, "%s", _xml_add_name); + recipe.MashStep[_xml_mashsteps].Name[0] = '\0'; + strncat(recipe.MashStep[_xml_mashsteps].Name, _xml_add_name, 31); recipe.MashStep[_xml_mashsteps].Type = _xml_add_type; recipe.MashStep[_xml_mashsteps].Temperature = _xml_add_temp; recipe.MashStep[_xml_mashsteps].Resttime = _xml_add_time; @@ -444,7 +449,7 @@ size_t bytes; uint8_t *dst; uint16_t y; - char filename[256], newname[256]; + char filename[288], newname[288]; int rc; switch (Main_Screen) { @@ -459,8 +464,8 @@ if (strstr(de->d_name, ".xml") || strstr(de->d_name, ".XML")) { _fg = TFT_YELLOW; TFT_print(de->d_name, 2, y); - snprintf(filename, 255, "/sdcard/recipe/%s", de->d_name); - snprintf(newname, 255, "/sdcard/recipe/%s", de->d_name); + snprintf(filename, 287, "/sdcard/recipe/%s", de->d_name); + snprintf(newname, 287, "/sdcard/recipe/%s", de->d_name); newname[strlen(newname) -2] = 'o'; newname[strlen(newname) -1] = 'k'; rc = ParseRecipe(filename, de->d_name); @@ -512,7 +517,7 @@ uint8_t *dst; int mashsteps; uint16_t y; - char tmp[32]; + char tmp[64]; float mintemp; switch (Main_Screen) { diff -r 38e1c91bfd88 -r 756d1a63d129 main/task_tft.c --- a/main/task_tft.c Tue Jul 02 11:00:27 2019 +0200 +++ b/main/task_tft.c Tue Jul 02 12:10:23 2019 +0200 @@ -15,7 +15,7 @@ time_t now; ///< Current time time_t last = 0; ///< Last time struct tm timeinfo; ///< Current time structure -char s_timer[10]; ///< Timer string buffer +char s_timer[16]; ///< Timer string buffer char s_top_msg[64]; ///< Top message string buffer extern float stageTemp; @@ -219,7 +219,7 @@ _fg = TFT_GREEN; TFT_setFont(FONT_7SEG, NULL); set_7seg_font_atrib(12, 2, 1, TFT_DARKGREY); - snprintf(s_timer, 9, "%02d:%02d:%02d", Hours, Minutes, Seconds); + snprintf(s_timer, 15, "%02d:%02d:%02d", Hours, Minutes, Seconds); TFT_print(s_timer, X, Y); _oldTime = Time; snprintf(msg, 31, "{\"timer\":\"%s\"}", s_timer); @@ -231,7 +231,7 @@ void TopMessage(char *text) { - char msg[64]; + char msg[96]; snprintf(s_top_msg, 63, "%s", text); _fg = TFT_YELLOW; @@ -240,7 +240,7 @@ TFT_fillRect(0, 0, 319, 25, TFT_NAVY); TFT_print(s_top_msg, CENTER, 2); font_transparent = 0; - snprintf(msg, 63, "{\"top_msg\":\"%s\"}", s_top_msg); + snprintf(msg, 95, "{\"top_msg\":\"%s\"}", s_top_msg); ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); } @@ -248,7 +248,7 @@ void MLT_info(int x, int y, bool update) { - char ctemp[16], csp[16], cpower[16], msg[32]; + char ctemp[16], csp[16], cpower[16], msg[96]; static char ltemp[16], lsp[16], lpower[16]; bool con, cpwr, cpump = false; static bool lon, lpwr, lpump; @@ -290,7 +290,7 @@ TFT_fillCircle(x + 166, y + 11, 8, _bg); } lon = con; - snprintf(msg, 31, "{\"mlt_led\":\"%s\"}", con ? "1":"0"); + snprintf(msg, 95, "{\"mlt_led\":\"%s\"}", con ? "1":"0"); ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); } @@ -302,7 +302,7 @@ TFT_fillCircle(x + 146, y + 11, 8, _bg); } lpump = cpump; - snprintf(msg, 31, "{\"pump_led\":\"%s\"}", cpump ? "1":"0"); + snprintf(msg, 95, "{\"pump_led\":\"%s\"}", cpump ? "1":"0"); ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); } @@ -315,7 +315,7 @@ TFT_fillCircle(x + 126, y + 11, 8, _bg); } lpwr = cpwr; - snprintf(msg, 31, "{\"hlt_led\":\"%s\"}", cpwr ? "1":"0"); + snprintf(msg, 95, "{\"hlt_led\":\"%s\"}", cpwr ? "1":"0"); ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); } } @@ -324,7 +324,7 @@ TFT_setFont(USER_FONT, "/spiffs/fonts/Grotesk24x48.fon"); TFT_print(ctemp, x + 5, y + 23); strncpy(ltemp, ctemp, 16); - snprintf(msg, 31, "{\"mlt_pv\":\"%s\"}", ctemp); + snprintf(msg, 95, "{\"mlt_pv\":\"%s\"}", ctemp); ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); } @@ -333,14 +333,14 @@ TFT_clearStringRect(x + 5, y + 70, (char *)"123.45 sp"); TFT_print(csp, x + 5, y + 70); strncpy(lsp, csp, 16); - snprintf(msg, 31, "{\"mlt_sp\":\"%s\"}", csp); + snprintf(msg, 95, "{\"mlt_sp\":\"%s\"}", csp); ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); } if (strcmp(cpower, lpower) || (! update)) { TFT_clearStringRect(x + 120, y + 70, (char *)"100%"); TFT_print(cpower, x + 120, y + 70); strncpy(lpower, cpower, 16); - snprintf(msg, 31, "{\"mlt_power\":\"%s\"}", cpower); + snprintf(msg, 95, "{\"mlt_power\":\"%s\"}", cpower); ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); } } @@ -349,7 +349,7 @@ void HLT_info(int x, int y, bool update, bool small) { - char ctemp[16], csp[16], cpower[16], msg[32]; + char ctemp[16], csp[16], cpower[16], msg[96]; static char ltemp[16], lsp[16], lpower[16]; bool con = false; static bool lon; @@ -391,7 +391,7 @@ TFT_fillCircle(x + 166, y + 11, 8, _bg); } lon = con; - snprintf(msg, 31, "{\"hlt_led\":\"%s\"}", con ? "1":"0"); + snprintf(msg, 95, "{\"hlt_led\":\"%s\"}", con ? "1":"0"); ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); } @@ -404,7 +404,7 @@ TFT_print(ctemp, x + 5, y + 23); } strncpy(ltemp, ctemp, 16); - snprintf(msg, 31, "{\"hlt_pv\":\"%s\"}", ctemp); + snprintf(msg, 95, "{\"hlt_pv\":\"%s\"}", ctemp); ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); } @@ -414,14 +414,14 @@ TFT_clearStringRect(x + 5, y + H, (char *)"123.45 sp"); TFT_print(csp, x + 5, y + H); strncpy(lsp, csp, 16); - snprintf(msg, 31, "{\"hlt_sp\":\"%s\"}", csp); + snprintf(msg, 95, "{\"hlt_sp\":\"%s\"}", csp); ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); } if (strcmp(cpower, lpower) || (! update)) { TFT_clearStringRect(x + 120, y + H, (char *)"100%"); TFT_print(cpower, x + 120, y + H); strncpy(lpower, cpower, 16); - snprintf(msg, 31, "{\"hlt_power\":\"%s\"}", cpower); + snprintf(msg, 95, "{\"hlt_power\":\"%s\"}", cpower); ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); } } @@ -437,7 +437,7 @@ counts = 1; // Prevent division by zero. if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { - snprintf(json_log->time, 8, "%02d:%02d", Hour, Minute); + snprintf(json_log->time, 11, "%02d:%02d", Hour, Minute); json_log->mlt_sp = driver_state->mlt_sp; json_log->mlt_pv = driver_state->mlt_pv; json_log->mlt_power = power_MLT / counts; @@ -490,7 +490,7 @@ void task_tft(void *pvParameter) { - char msg[64]; + char msg[96]; ESP_LOGI(TAG, "Initialize TFT/Touch task"); @@ -527,7 +527,7 @@ * With each screenchange, remove the timer too. */ Sub_Screen = 0; - snprintf(msg, 63, "{\"main\":\"%d\",\"sub\":\"%d\",\"timer\":\"\"}", Main_Screen, Sub_Screen); + snprintf(msg, 95, "{\"main\":\"%d\",\"sub\":\"%d\",\"timer\":\"\"}", Main_Screen, Sub_Screen); ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); ESP_LOGI(TAG, "Change screen %d to %d", Old_Screen, Main_Screen); @@ -673,12 +673,14 @@ } if (System_TimeOk && (now != last)) { last = now; - strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo); + //strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo); + strftime(strftime_buf, sizeof(strftime_buf), "%a %e %b %Y %T", &timeinfo); _bg = TFT_BLACK; _fg = TFT_ORANGE; TFT_setFont(DEJAVU18_FONT, NULL); - TFT_print(strftime_buf, CENTER, 125); - snprintf(msg, 63, "{\"timer\":\"%s\"}", strftime_buf); // Fix string termination and only send once/second. + snprintf(msg, 95, " %s ", strftime_buf); + TFT_print(msg, CENTER, 125); + snprintf(msg, 95, "{\"timer\":\"%s\"}", strftime_buf); // Fix string termination and only send once/second. ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); } break; diff -r 38e1c91bfd88 -r 756d1a63d129 main/task_wifi.c --- a/main/task_wifi.c Tue Jul 02 11:00:27 2019 +0200 +++ b/main/task_wifi.c Tue Jul 02 12:10:23 2019 +0200 @@ -241,9 +241,9 @@ if (tcpip_adapter_get_ip_info(ESP_IF_WIFI_STA, &ip) == 0) { if (xSemaphoreTake(xSemaphoreWiFi, 10) == pdTRUE) { wifi_state->STA_online = true; - snprintf(wifi_state->STA_ip, 15, IPSTR, IP2STR(&ip.ip)); - snprintf(wifi_state->STA_nm, 15, IPSTR, IP2STR(&ip.netmask)); - snprintf(wifi_state->STA_gw, 15, IPSTR, IP2STR(&ip.gw)); + snprintf(wifi_state->STA_ip, 16, IPSTR, IP2STR(&ip.ip)); + snprintf(wifi_state->STA_nm, 16, IPSTR, IP2STR(&ip.netmask)); + snprintf(wifi_state->STA_gw, 16, IPSTR, IP2STR(&ip.gw)); xSemaphoreGive(xSemaphoreWiFi); } } @@ -606,7 +606,7 @@ bool WiFi_Init(void) { - char pwd[65], pmpt[32]; + char pwd[65], pmpt[96]; switch (Main_Screen) { case MAIN_TOOLS_SETUP_WIFI: @@ -688,7 +688,7 @@ case MAIN_TOOLS_SETUP_WIFI_NEW: TopMessage((char *)"WiFi nieuw"); - snprintf(pmpt, 32, "Password for %s", _wifi_ssid); + snprintf(pmpt, 95, "Password for %s", _wifi_ssid); pwd[0] = '\0'; EditTextMin(pmpt, pwd, 64, 8); /* diff -r 38e1c91bfd88 -r 756d1a63d129 main/task_wifi.h --- a/main/task_wifi.h Tue Jul 02 11:00:27 2019 +0200 +++ b/main/task_wifi.h Tue Jul 02 12:10:23 2019 +0200 @@ -33,9 +33,9 @@ bool STA_online; ///< Connected and online. char STA_ssid[33]; ///< Connected to this SSID. int8_t STA_rssi; ///< Signal strength. - char STA_ip[16]; ///< IP address. - char STA_nm[16]; ///< IP netmask. - char STA_gw[16]; ///< IP gateway. + char STA_ip[17]; ///< IP address. + char STA_nm[17]; ///< IP netmask. + char STA_gw[17]; ///< IP gateway. } WIFI_State; /** diff -r 38e1c91bfd88 -r 756d1a63d129 sdkconfig --- a/sdkconfig Tue Jul 02 11:00:27 2019 +0200 +++ b/sdkconfig Tue Jul 02 12:10:23 2019 +0200 @@ -98,7 +98,7 @@ # CONFIG_COMPILER_STACK_CHECK_MODE_ALL is not set # CONFIG_COMPILER_STACK_CHECK is not set # CONFIG_COMPILER_WARN_WRITE_STRINGS is not set -CONFIG_COMPILER_DISABLE_GCC8_WARNINGS=y +# CONFIG_COMPILER_DISABLE_GCC8_WARNINGS is not set # CONFIG_ESP32_APPTRACE_DEST_TRAX is not set CONFIG_ESP32_APPTRACE_DEST_NONE=y # CONFIG_ESP32_APPTRACE_ENABLE is not set @@ -574,7 +574,7 @@ # CONFIG_STACK_CHECK_ALL is not set # CONFIG_STACK_CHECK is not set # CONFIG_WARN_WRITE_STRINGS is not set -CONFIG_DISABLE_GCC8_WARNINGS=y +# CONFIG_DISABLE_GCC8_WARNINGS is not set CONFIG_BTDM_CONTROLLER_BLE_MAX_CONN_EFF=0 CONFIG_BTDM_CONTROLLER_BR_EDR_MAX_ACL_CONN_EFF=0 CONFIG_BTDM_CONTROLLER_BR_EDR_MAX_SYNC_CONN_EFF=0