Crudely bounds check some naked fscanf("%s") parsing. Fixes #79, mostly.
This commit is contained in:
parent
c47661f07e
commit
d1cbb9cf60
|
@ -72,7 +72,7 @@ void cs_machinit(void *vp)
|
||||||
/* Find piece that is relevant for this phase. */
|
/* Find piece that is relevant for this phase. */
|
||||||
do {
|
do {
|
||||||
while (getc(f) != '\n');
|
while (getc(f) != '\n');
|
||||||
fscanf(f, "%s", s);
|
fscanf(f, "%99s", s);
|
||||||
} while (strcmp(s, "%%CS"));
|
} while (strcmp(s, "%%CS"));
|
||||||
|
|
||||||
/* Choose a set of instructions which must only be eliminated
|
/* Choose a set of instructions which must only be eliminated
|
||||||
|
|
|
@ -32,14 +32,14 @@ convert(mnemfile,itemfile)
|
||||||
newcl = TRUE;
|
newcl = TRUE;
|
||||||
printf("struct item_descr itemtab[] = {\n");
|
printf("struct item_descr itemtab[] = {\n");
|
||||||
for (;;) {
|
for (;;) {
|
||||||
fscanf(mnemfile,"%s%s%d",def,mnem1,&opc);
|
fscanf(mnemfile,"%19s%19s%d",def,mnem1,&opc);
|
||||||
/* read a line like "#define op_aar 1" */
|
/* read a line like "#define op_aar 1" */
|
||||||
if (feof(mnemfile)) break;
|
if (feof(mnemfile)) break;
|
||||||
if (strcmp(def,"#define") != 0) {
|
if (strcmp(def,"#define") != 0) {
|
||||||
error("bad mnemonic file, #define expected");
|
error("bad mnemonic file, #define expected");
|
||||||
}
|
}
|
||||||
if (newcl) {
|
if (newcl) {
|
||||||
fscanf(itemfile,"%s%s%d",mnem2,itemtype,&index);
|
fscanf(itemfile,"%19s%19s%d",mnem2,itemtype,&index);
|
||||||
/* read a line like "op_loc CONST 4" */
|
/* read a line like "op_loc CONST 4" */
|
||||||
}
|
}
|
||||||
if (feof(itemfile) || strcmp(mnem1,mnem2) != 0) {
|
if (feof(itemfile) || strcmp(mnem1,mnem2) != 0) {
|
||||||
|
|
|
@ -112,7 +112,7 @@ STATIC void ra_machinit(void *vp)
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
while(getc(f) != '\n');
|
while(getc(f) != '\n');
|
||||||
fscanf(f,"%s",s);
|
fscanf(f,"%99s",s);
|
||||||
if (strcmp(s,"%%RA") == 0)break;
|
if (strcmp(s,"%%RA") == 0)break;
|
||||||
}
|
}
|
||||||
fscanf(f,"%hd",®s_available[reg_any]);
|
fscanf(f,"%hd",®s_available[reg_any]);
|
||||||
|
|
|
@ -37,14 +37,14 @@ convert(mnemfile,classfile)
|
||||||
printf("\tNOCLASS,\tNOCLASS,\n");
|
printf("\tNOCLASS,\tNOCLASS,\n");
|
||||||
/* EM mnemonics start at 1, arrays in C at 0 */
|
/* EM mnemonics start at 1, arrays in C at 0 */
|
||||||
for (;;) {
|
for (;;) {
|
||||||
fscanf(mnemfile,"%s%s%d",def,mnem1,&opc);
|
fscanf(mnemfile,"%9s%9s%d",def,mnem1,&opc);
|
||||||
/* read a line like "#define op_aar 1" */
|
/* read a line like "#define op_aar 1" */
|
||||||
if (feof(mnemfile)) break;
|
if (feof(mnemfile)) break;
|
||||||
if (strcmp(def,"#define") != 0) {
|
if (strcmp(def,"#define") != 0) {
|
||||||
error("bad mnemonic file, #define expected");
|
error("bad mnemonic file, #define expected");
|
||||||
}
|
}
|
||||||
if (newcl) {
|
if (newcl) {
|
||||||
fscanf(classfile,"%s%d%d",mnem2,&src,&res);
|
fscanf(classfile,"%9s%d%d",mnem2,&src,&res);
|
||||||
/* read a line like "op_loc 8 1" */
|
/* read a line like "op_loc 8 1" */
|
||||||
}
|
}
|
||||||
if (feof(classfile) || strcmp(mnem1,mnem2) != 0) {
|
if (feof(classfile) || strcmp(mnem1,mnem2) != 0) {
|
||||||
|
|
|
@ -60,7 +60,7 @@ STATIC void sp_machinit(void *vp)
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
while(getc(f) != '\n');
|
while(getc(f) != '\n');
|
||||||
fscanf(f,"%s",s);
|
fscanf(f,"%99s",s);
|
||||||
if (strcmp(s,"%%SP") == 0)break;
|
if (strcmp(s,"%%SP") == 0)break;
|
||||||
}
|
}
|
||||||
fscanf(f,"%d",&globl_sp_allowed);
|
fscanf(f,"%d",&globl_sp_allowed);
|
||||||
|
|
|
@ -61,7 +61,7 @@ void sr_machinit(void *vp)
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
while(getc(f) != '\n');
|
while(getc(f) != '\n');
|
||||||
fscanf(f,"%s",s);
|
fscanf(f,"%99s",s);
|
||||||
if (strcmp(s,"%%SR") == 0)break;
|
if (strcmp(s,"%%SR") == 0)break;
|
||||||
}
|
}
|
||||||
fscanf(f,"%d",&ovfl_harmful);
|
fscanf(f,"%d",&ovfl_harmful);
|
||||||
|
|
|
@ -64,7 +64,7 @@ STATIC void ud_machinit(void *vp)
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
while(getc(f) != '\n');
|
while(getc(f) != '\n');
|
||||||
fscanf(f,"%s",s);
|
fscanf(f,"%99s",s);
|
||||||
if (strcmp(s,"%%UD") == 0)break;
|
if (strcmp(s,"%%UD") == 0)break;
|
||||||
}
|
}
|
||||||
globl_cond_tab = getcondtab(f);
|
globl_cond_tab = getcondtab(f);
|
||||||
|
|
|
@ -52,7 +52,7 @@ main(argc, argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Start reading the input file */
|
/* Start reading the input file */
|
||||||
while (fscanf(ifp, "%s %s", mnem, flgs) >= 0) {
|
while (fscanf(ifp, "%7s %7s", mnem, flgs) >= 0) {
|
||||||
int i;
|
int i;
|
||||||
char *p;
|
char *p;
|
||||||
char *base;
|
char *base;
|
||||||
|
|
|
@ -55,7 +55,7 @@ main(argc, argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Start reading the input file */
|
/* Start reading the input file */
|
||||||
while (fscanf(ifp, "%s %s", mnem, flgs) >= 0) {
|
while (fscanf(ifp, "%7s %7s", mnem, flgs) >= 0) {
|
||||||
int i;
|
int i;
|
||||||
char *p;
|
char *p;
|
||||||
char *base;
|
char *base;
|
||||||
|
|
Loading…
Reference in a new issue