Browse Source

.csparam: Add some safeguarding against wrong input and crash,

allow multiple parameters in a .csparam row (like .param).
pre-master-46
Holger Vogt 3 years ago
parent
commit
823465ceb8
  1. 30
      src/frontend/inp.c

30
src/frontend/inp.c

@ -890,23 +890,35 @@ inp_spsource(FILE *fp, bool comfile, char *filename, bool intfile)
/* handle .if ... .elseif ... .else ... .endif statements. */
dotifeval(deck);
/* get csparams and create vectors, available
in plot 'const' of a .control section */
for (dd = deck; dd; dd = dd->nextcard) {
/* get csparams and create vectors, being
available in .control section, in plot 'const' */
if (ciprefix(".csparam", dd->line)) {
wordlist *wlist = NULL;
char *cstoken[3];
int i;
dd->line[0] = '*';
s = skip_ws(dd->line + 8);
cstoken[0] = gettok_char(&s, '=', FALSE, FALSE);
cstoken[1] = gettok_char(&s, '=', TRUE, FALSE);
cstoken[2] = gettok(&s);
for (i = 3; --i >= 0; ) {
wlist = wl_cons(cstoken[i], wlist);
while (s && *s) {
cstoken[0] = gettok_char(&s, '=', FALSE, FALSE);
cstoken[1] = gettok_char(&s, '=', TRUE, FALSE);
cstoken[2] = gettok(&s);
/* guard against buggy input line */
if (!cstoken[0] || !cstoken[1] || !cstoken[2] || strchr(cstoken[2],'=')) {
tfree(cstoken[0]);
tfree(cstoken[1]);
tfree(cstoken[2]);
fprintf(stderr, "Warning: bad csparam definition, skipped!\n");
fprintf(stderr, " in line %d, .%s\n\n", dd->linenum, dd->line + 1);
continue;
}
for (i = 3; --i >= 0; ) {
wlist = wl_cons(cstoken[i], wlist);
}
com_let(wlist);
wl_free(wlist);
wlist = NULL;
}
com_let(wlist);
wl_free(wlist);
}
}

Loading…
Cancel
Save