Commit 592a153a by kollo

Fixed crash (READ with wrong number of indicies) Emil Schweickerdt 2016-12-31

parent b3aec581
......@@ -2260,8 +2260,8 @@ static void c_if(PARAMETER *plist,int e) {
int j=pcode[i].opcode&PM_COMMS;
int e=make_pliste3(comms[j].pmin,comms[j].pmax,(unsigned short *)comms[j].pliste,
pcode[i].ppointer,&plist,pcode[i].panzahl);
(comms[j].routine)(plist,e);
if(e!=-1) free_pliste(e,plist);
if(e>=0) (comms[j].routine)(plist,e);
free_pliste(e,plist);
}
// else printf("neues Ziel ist: %d <%s>\n",pc,program[pc]);
}
......
......@@ -491,6 +491,7 @@ int make_pliste2(int pmin,int pmax,unsigned short *pliste,char *n, PARAMETER **p
/*Hier Ergaenzungen von pre-pliste zu aktueller (Zu Laufzeit).
Jetzt koennen variableninhalte als fix betrachtet werden.
Return: 0 = alles OK, -1 = Fehler
*/
int make_parameter_stage3(PARAMETER *pin,unsigned short ap,PARAMETER *pret) {
unsigned short ip=pin->typ;
......@@ -505,7 +506,7 @@ int make_parameter_stage3(PARAMETER *pin,unsigned short ap,PARAMETER *pret) {
if(ip==PL_LABEL || ip==PL_PROC) {
pret->integer=pin->integer;
pret->arraytyp=pin->arraytyp; /* Typ */
} else PARERR();
} else {PARERR();return(-1);}
break;
case PL_FILENR:
case PL_INT: /* Integer */
......@@ -537,7 +538,7 @@ int make_parameter_stage3(PARAMETER *pin,unsigned short ap,PARAMETER *pret) {
mpz_init(*((ARBINT *)pret->pointer));
mpz_set(*((ARBINT *)pret->pointer),*((ARBINT *)pin->pointer));
break;
default: PARERR();
default: {PARERR();return(-1);}
}
break;
case PL_CFAI: /* Float oder complex oder arbint */
......@@ -560,7 +561,7 @@ int make_parameter_stage3(PARAMETER *pin,unsigned short ap,PARAMETER *pret) {
mpz_init(*((ARBINT *)pret->pointer));
mpz_set(*((ARBINT *)pret->pointer),*((ARBINT *)pin->pointer));
break;
default: PARERR();
default: {PARERR();return(-1);}
}
break;
case PL_CF: /* Float oder complex oder arbint */
......@@ -582,7 +583,7 @@ int make_parameter_stage3(PARAMETER *pin,unsigned short ap,PARAMETER *pret) {
pret->real=mpz_get_d(*((ARBINT *)pin->pointer));
pret->typ=PL_FLOAT;
break;
default: PARERR();
default: {PARERR();return(-1);}
}
break;
case PL_FLOAT: /* Float oder Number */
......@@ -644,7 +645,7 @@ int make_parameter_stage3(PARAMETER *pin,unsigned short ap,PARAMETER *pret) {
mpz_set(*((ARBINT *)pret->pointer),*((ARBINT *)pin->pointer));
break;
case PL_STRING: *((STRING *)&(pret->integer))=double_string((STRING *)&(pin->integer)); break;
default: PARERR();
default: {PARERR();return(-1);}
}
break;
case PL_STRING: /* String */
......@@ -655,7 +656,7 @@ int make_parameter_stage3(PARAMETER *pin,unsigned short ap,PARAMETER *pret) {
} else if(ip==PL_STRING) {
*((STRING *)&(pret->integer))=double_string((STRING *)&(pin->integer));
pret->typ=PL_STRING;
} else PARERR();
} else {PARERR();return(-1);}
break;
case PL_ARRAY: /* Array */
case PL_IARRAY: /* Int-Array */
......@@ -700,7 +701,7 @@ int make_parameter_stage3(PARAMETER *pin,unsigned short ap,PARAMETER *pret) {
printf("line %d: Error: Parameter is wrong (typ=%x) ARRAY (need to be $%x). Cannot convert.\n",pc,ip,ap);
dump_parameterlist(pin,1);
}
} else PARERR();
} else {PARERR();return(-1);}
break;
case PL_VAR: /* Variable */
case PL_NVAR: /* Variable */
......@@ -723,10 +724,11 @@ int make_parameter_stage3(PARAMETER *pin,unsigned short ap,PARAMETER *pret) {
if(pin->panzahl) {
indexliste=malloc(pin->panzahl*sizeof(int));
get_indexliste(pin->ppointer,indexliste,pin->panzahl);
// printf("Es sind %d indizien da.\n",pin[i].panzahl);
// printf("Es sind %d indizien da.\n",pin->panzahl);
} else indexliste=NULL;
pret->pointer=varptr_indexliste(&variablen[vnr],indexliste,pin->panzahl);
free(indexliste);
if(pret->pointer==NULL) return(-1);
} else pret->pointer=pin->pointer;
// printf("Variable uebergeben. %d %s\n",vnr,varinfo(&variablen[vnr]));
......@@ -737,40 +739,43 @@ int make_parameter_stage3(PARAMETER *pin,unsigned short ap,PARAMETER *pret) {
else if(ip==PL_EVAL) pret->arraytyp=keyword2num(pin->pointer);
if(ip==PL_EVAL ||ip==PL_KEY) *((STRING *)&(pret->integer))=create_string(pin->pointer);
else if(ip==PL_LEER) *((STRING *)&(pret->integer))=create_string("");
else PARERR();
else {PARERR();return(-1);}
break;
case PL_EVAL: /* Keyword */
if(ip==PL_LEER) pret->typ=PL_LEER;
else if(ip==PL_EVAL ||ip==PL_KEY) {
pret->arraytyp=pin->arraytyp;
*((STRING *)&(pret->integer))=create_string(pin->pointer);
} else PARERR();
} else {PARERR();return(-1);}
break;
default:
printf("unknown parameter type. -->$%x \n",ap);
printf("ERROR: unknown parameter type. -->$%x \n",ap);
return(-1);
}
return(0);
}
/* Rueckgabe ist die Anzahl der prozessierten Parameter
oder -1 wenn ein Fehler aufgetreten ist..
*/
int make_pliste3(int pmin,int pmax,unsigned short *pliste,PARAMETER *pin, PARAMETER **pout,int ii){
PARAMETER *pret;
unsigned short ap;
int i;
int anzpar;
int i=0,anzpar,err=0;
if(pmax==-1) anzpar=ii;
else anzpar=min(ii,pmax);
// printf("PARAMETER vervollstaendigen: (%d) %d\n",ii,anzpar);
*pout=pret=calloc(anzpar,sizeof(PARAMETER));
i=0;
while(i<anzpar) {
if(i>pmin && pmax==-1) ap=pliste[pmin];
else ap=pliste[i];
// printf("Par #%d: typ1=%x typ2=%x %s\n",i,ap,ip,plist_paramter(&pin[i]));
make_parameter_stage3(&pin[i],ap,&pret[i]);
err|=make_parameter_stage3(&pin[i],ap,&pret[i]);
i++;
}
if(err) return(-1);
return(i);
}
......
......@@ -363,7 +363,7 @@ if(searchchr2_multi(s,"*/^")!=NULL) {
a=0;
xberror(42,s); /* Zu wenig Parameter */
}
if(e!=-1) free_pliste(e,plist);
free_pliste(e,plist);
// printf("a=%d\n",a);
return(a);
}
......@@ -707,7 +707,7 @@ COMPLEX complex_parser(const char *funktion) {
default: xberror(13,s); /* Type mismatch */
}
} else xberror(42,s); /* Zu wenig Parameter */
if(e!=-1) free_pliste(e,plist);
free_pliste(e,plist);
return(ret);
}
......@@ -1155,7 +1155,7 @@ void arbint_parser(const char *funktion, ARBINT ret) {
default: xberror(13,s); /* Type mismatch */
}
}
if(e!=-1) free_pliste(e,plist);
free_pliste(e,plist);
return;
}
......@@ -1434,7 +1434,7 @@ ARRAY array_parser(const char *funktion) { /* Array-Parser */
PARAMETER *plist;
int e=make_pliste(pafuncs[i].pmin,pafuncs[i].pmax,(unsigned short *)pafuncs[i].pliste,pos,&plist);
ARRAY a=(pafuncs[i].routine)(plist,e);
if(e!=-1) free_pliste(e,plist);
free_pliste(e,plist);
return(a);
} else if(pafuncs[i].pmax==1 && (pafuncs[i].opcode&FM_TYP)==F_AQUICK) {
ARRAY ergebnis,a=array_parser(pos);
......@@ -1563,7 +1563,7 @@ STRING string_parser(const char *funktion) {
PARAMETER *plist;
int e=make_pliste(psfuncs[i].pmin,psfuncs[i].pmax,(unsigned short *)psfuncs[i].pliste,pos,&plist);
ergebnis=(psfuncs[i].routine)(plist,e);
if(e!=-1) free_pliste(e,plist);
free_pliste(e,plist);
} else if(psfuncs[i].pmax==1 && (psfuncs[i].opcode&FM_TYP)==F_DQUICK) {
ergebnis=(psfuncs[i].routine)(parser(pos));
} else if(psfuncs[i].pmax==1 && (psfuncs[i].opcode&FM_TYP)==F_IQUICK) {
......
......@@ -466,7 +466,7 @@ STATIC int vm_sfunc(PARAMETER *sp,int i, int anzarg) { /* */
int e=make_pliste3(psfuncs[i].pmin,psfuncs[i].pmax,(unsigned short *)psfuncs[i].pliste,
&sp[0],&plist,anzarg);
s=(psfuncs[i].routine)(plist,anzarg);
if(e!=-1) free_pliste(e,plist);
free_pliste(e,plist);
e=anzarg;
while(--e>=0) free_parameter(&sp[e]);
sp[0].pointer=s.pointer;
......@@ -619,7 +619,7 @@ STATIC int vm_func(PARAMETER *sp,int i, int anzarg) { /* */
break;
default: xberror(13,""); /* Type mismatch */
}
if(e!=-1) free_pliste(e,plist);
free_pliste(e,plist);
e=anzarg;
while(--e>=0) free_parameter(&sp[e]);
*sp=*rpar;free(rpar);
......@@ -757,8 +757,8 @@ STATIC int vm_comm(PARAMETER *sp,int i, int anzarg) { /* */
PARAMETER *plist;
int e=make_pliste3(comms[i].pmin,comms[i].pmax,(unsigned short *)comms[i].pliste,
&sp[-anzarg],&plist,anzarg);
(comms[i].routine)(plist,e);
if(e!=-1) free_pliste(e,plist);
if(e>=0) (comms[i].routine)(plist,e);
free_pliste(e,plist);
e=anzarg;
// printf("Parameters to clear: (%d)\n",e);
// dump_parameterlist(&sp[-e],e);
......
......@@ -1110,7 +1110,7 @@ void kommando(char *cmd) {
PARAMETER *plist;
int e=make_pliste(comms[i].pmin,comms[i].pmax,(unsigned short *)comms[i].pliste,w2,&plist);
if(e>=comms[i].pmin) (comms[i].routine)(plist,e);
if(e!=-1) free_pliste(e,plist);
free_pliste(e,plist);
}
return;
default: xberror(38,w1); /* Befehl im Direktmodus nicht moeglich */
......@@ -1242,8 +1242,8 @@ void programmlauf(){
int e=make_pliste3(pcode[opc].panzahl,pcode[opc].panzahl,ptypliste,
pcode[opc].ppointer,&plist,pcode[opc].panzahl);
call_sub_with_parameterlist(pcode[opc].integer,plist,pcode[opc].panzahl);
if(e!=-1) free_pliste(e,plist);
if(e>=0) call_sub_with_parameterlist(pcode[opc].integer,plist,pcode[opc].panzahl);
free_pliste(e,plist);
}
} break;
......@@ -1262,8 +1262,8 @@ void programmlauf(){
int i=pcode[opc].opcode&PM_COMMS;
int e=make_pliste3(comms[i].pmin,comms[i].pmax,(unsigned short *)comms[i].pliste,
pcode[opc].ppointer,&plist,pcode[opc].panzahl);
(comms[i].routine)(plist,e);
if(e!=-1) free_pliste(e,plist);
if(e>=0) (comms[i].routine)(plist,e);
free_pliste(e,plist);
} break;
default:
printf("something is wrong: %x %s\n",(int)pcode[opc].opcode,program[opc]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment