Преглед изворни кода

web: fixed memory corruption due to long settings field

the fix is suboptimal as it will break after someone would increase the
max field size even further, but i'm not aware of a simple way to find
the longest field in a deep nested struct
Sergey Alirzaev пре 4 година
родитељ
комит
4ed5ee6c84

+ 0 - 2
modules/HTTP_Server/web_params_api.c

@@ -49,7 +49,6 @@ uint32_t JumpAddress;
   */
 char *HTTP_GetParamsPage(uint32_t reqNum, char *bufIn, char *bufOut, uint16_t lenBufIn, uint16_t *lenBufOut)
 {
-    char str[40];
     uint8_t len;
 
     (void)bufIn;
@@ -83,7 +82,6 @@ char *HTTP_GetParamsPage(uint32_t reqNum, char *bufIn, char *bufOut, uint16_t le
   */
 char *HTTP_GetSettingsPage(uint32_t reqNum, char *bufIn, char *bufOut, uint16_t lenBufIn, uint16_t *lenBufOut)
 {
-    char str[30];
     uint8_t len;
 
     memset(bufOut, 0, SEND_BUF_MAX_LEN);

+ 1 - 0
modules/HTTP_Server/web_params_api.h

@@ -18,6 +18,7 @@
 
 #define JSON_ADD_TAG(tag, get_param, cjson_param) \
   do { \
+    char str[SETTINGS_FIELD_MAX_LEN]; \
     memset(str, 0, sizeof(str)); \
     get_param(str, &len); \
     if (strncmp(tag, "tn_enabled", sizeof(tag)) == 0  \

+ 1 - 0
modules/settings_api.h

@@ -327,6 +327,7 @@ typedef struct {
 	ip_addr_t server_ip;
 	u16_t server_port;
 	char remote_path[100];
+#define SETTINGS_FIELD_MAX_LEN 100
 	char user[30];
 	char pass[30];
 } FTP_Update_t;