Merge pull request #14268 from gemu2015/scripter_fix

fix memory corruption
This commit is contained in:
Theo Arends 2022-01-04 14:16:30 +01:00 committed by GitHub
commit 2121d8b273
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 38 additions and 18 deletions

View File

@ -689,7 +689,7 @@ char *script;
numflt++;
if (numflt>MAXFILT) {
if (imemptr) free(imemptr);
if (strings_p) free(strings_p);
if (strings_op) free(strings_op);
return -6;
}
} else {
@ -716,7 +716,7 @@ char *script;
nvars++;
if (nvars>MAXNVARS) {
if (imemptr) free(imemptr);
if (strings_p) free(strings_p);
if (strings_op) free(strings_op);
return -1;
}
if (vtypes[vars].bits.is_filter) {
@ -750,14 +750,14 @@ char *script;
svars++;
if (svars>MAXSVARS) {
if (imemptr) free(imemptr);
if (strings_p) free(strings_p);
if (strings_op) free(strings_op);
return -2;
}
}
vars++;
if (vars>MAXVARS) {
if (imemptr) free(imemptr);
if (strings_p) free(strings_p);
if (strings_op) free(strings_op);
return -3;
}
}
@ -809,7 +809,7 @@ char *script;
script_mem = (uint8_t*)special_malloc(script_mem_size);
if (!script_mem) {
if (imemptr) free(imemptr);
if (strings_p) free(strings_p);
if (strings_op) free(strings_op);
return -4;
}
@ -891,7 +891,7 @@ char *script;
if (index > MAXVNSIZ) {
free(glob_script_mem.script_mem);
if (imemptr) free(imemptr);
if (strings_p) free(strings_p);
if (strings_op) free(strings_op);
return -5;
}
}
@ -989,7 +989,7 @@ char *script;
if (imemptr) {
free(imemptr);
if (strings_p) free(strings_p);
if (strings_op) free(strings_op);
}
return err;
}
@ -1408,7 +1408,7 @@ uint32_t ts2ts(struct FE_TM *tm, char *ts) {
tm->secs = strtol(ts, &ts, 10);
return 0;
} else {
// german excel fromat 16.12.20 15:36
// german excel format 16.12.20 15:36
tm->day = strtol(ts, &ts, 10);
ts++;
tm->month = strtol(ts, &ts, 10);
@ -1444,10 +1444,18 @@ struct FE_TM tm;
// convert tasmota time stamp to ul seconds
uint32_t tstamp2l(char *ts) {
struct FE_TM tm;
struct tm tmx;
uint8_t mode = ts2ts(&tm, ts);
ts2ts(&tm, ts);
tmx.tm_sec = tm.secs;
tmx.tm_min = tm.mins;
tmx.tm_hour = tm.hour;
tmx.tm_mon = tm.month - 1;
tmx.tm_year = tm.year + 100;
tmx.tm_mday = tm.day;
time_t tmd = mktime(&tmx);
return (tm.year*365*86400)+(tm.month*31*86400)+(tm.day*86400)+(tm.hour*3600)+(tm.mins*60)+tm.secs;
return tmd;
}
// assume 1. entry is timestamp, others are tab delimited values until LF
@ -1496,6 +1504,7 @@ int32_t extract_from_file(uint8_t fref, char *ts_from, char *ts_to, int8_t coff
glob_script_mem.files[fref].seek(0, SeekSet);
uint32_t tsfrom = tstamp2l(ts_from);
uint32_t tsto = tstamp2l(ts_to);
//AddLog(LOG_LEVEL_INFO, PSTR("from: %d to: %d"),tsfrom, tsto);
uint16_t lines = 0;
uint16_t rlines = 0;
float summs[numa];
@ -2789,7 +2798,8 @@ chknext:
if (glob_script_mem.file_flags[index].is_open) {
char dstr[24];
for (uint32_t cnt = 0; cnt < alen; cnt++) {
dtostrfd(*fa, glob_script_mem.script_dprec, dstr);
//dtostrfd(*fa, glob_script_mem.script_dprec, dstr);
ext_snprintf_P(dstr, sizeof(dstr), PSTR("%*_f"), -glob_script_mem.script_dprec, fa);
fa++;
if (cnt < (alen - 1)) {
strcat(dstr,"\t");
@ -7634,7 +7644,7 @@ const char SCRIPT_MSG_GOPT2[] PROGMEM =
"showRowNumber:true,sort:'disable',allowHtml:true,width:'100%%',height:'100%%',cssClassNames:cssc";
const char SCRIPT_MSG_GOPT3[] PROGMEM =
"title:'%s',isStacked:false,vAxes:{0:{maxValue:%d},1:{maxValue:%d}},series:{0:{targetAxisIndex:0},1:{targetAxisIndex:1}}%s";
"title:'%s',isStacked:false,vAxes:{0:{maxValue:%s},1:{maxValue:%s}},series:{0:{targetAxisIndex:0},1:{targetAxisIndex:1}}%s";
const char SCRIPT_MSG_GOPT4[] PROGMEM =
//"hAxis:{minValue:new Date(0,1,1,0,0),maxValue:new Date(0,1,2,0,0),format:'HH:mm'}";
@ -7644,7 +7654,7 @@ const char SCRIPT_MSG_GOPT5[] PROGMEM =
"new Date(0,0,0,%d,%d)";
const char SCRIPT_MSG_GOPT6[] PROGMEM =
"title:'%s',isStacked:false,vAxis:{viewWindow:{min:%d,max:%d}}%s";
"title:'%s',isStacked:false,vAxis:{viewWindow:{min:%s,max:%s}}%s";
const char SCRIPT_MSG_GTE1[] PROGMEM = "'%s'";
@ -8356,7 +8366,12 @@ exgc:
float max2;
lp = GetNumericArgument(lp, OPER_EQU, &max2, 0);
SCRIPT_SKIP_SPACES
snprintf_P(options, sizeof(options), SCRIPT_MSG_GOPT3, header, (uint32_t)max1, (uint32_t)max2, func);
char maxstr1[16];
dtostrfd(max1, 3, maxstr1);
char maxstr2[16];
dtostrfd(max2, 3, maxstr2);
//snprintf_P(options, sizeof(options), SCRIPT_MSG_GOPT3, header, (uint32_t)max1, (uint32_t)max2, func);
snprintf_P(options, sizeof(options), SCRIPT_MSG_GOPT3, header, maxstr1, maxstr2, func);
} else {
SCRIPT_SKIP_SPACES
if (ctype!='g') {
@ -8367,7 +8382,12 @@ exgc:
float max2;
lp = GetNumericArgument(lp, OPER_EQU, &max2, 0);
SCRIPT_SKIP_SPACES
snprintf_P(options, sizeof(options), SCRIPT_MSG_GOPT6, header, (uint32_t)max1, (uint32_t)max2, func);
char maxstr1[16];
dtostrfd(max1, 3, maxstr1);
char maxstr2[16];
dtostrfd(max2, 3, maxstr2);
//nprintf_P(options, sizeof(options), SCRIPT_MSG_GOPT6, header, (uint32_t)max1, (uint32_t)max2, func);
snprintf_P(options, sizeof(options), SCRIPT_MSG_GOPT6, header, maxstr1, maxstr2, func);
}
}
}