From: David Given Date: Sat, 2 Jun 2018 18:51:41 +0000 (+0200) Subject: Crudely bounds check some naked fscanf("%s") parsing. Fixes #79, mostly. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=d1cbb9cf60b7a1c58de934fc23539745cc94b700;p=ack.git Crudely bounds check some naked fscanf("%s") parsing. Fixes #79, mostly. --- diff --git a/util/ego/cs/cs_profit.c b/util/ego/cs/cs_profit.c index 2efabcb03..801e34319 100644 --- a/util/ego/cs/cs_profit.c +++ b/util/ego/cs/cs_profit.c @@ -72,7 +72,7 @@ void cs_machinit(void *vp) /* Find piece that is relevant for this phase. */ do { while (getc(f) != '\n'); - fscanf(f, "%s", s); + fscanf(f, "%99s", s); } while (strcmp(s, "%%CS")); /* Choose a set of instructions which must only be eliminated diff --git a/util/ego/ra/makeitems.c b/util/ego/ra/makeitems.c index bd9cf35f4..83f6703bd 100644 --- a/util/ego/ra/makeitems.c +++ b/util/ego/ra/makeitems.c @@ -32,14 +32,14 @@ convert(mnemfile,itemfile) newcl = TRUE; printf("struct item_descr itemtab[] = {\n"); 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" */ if (feof(mnemfile)) break; if (strcmp(def,"#define") != 0) { error("bad mnemonic file, #define expected"); } 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" */ } if (feof(itemfile) || strcmp(mnem1,mnem2) != 0) { diff --git a/util/ego/ra/ra.c b/util/ego/ra/ra.c index 643831f8d..0b1d5e493 100644 --- a/util/ego/ra/ra.c +++ b/util/ego/ra/ra.c @@ -112,7 +112,7 @@ STATIC void ra_machinit(void *vp) for (;;) { while(getc(f) != '\n'); - fscanf(f,"%s",s); + fscanf(f,"%99s",s); if (strcmp(s,"%%RA") == 0)break; } fscanf(f,"%hd",®s_available[reg_any]); diff --git a/util/ego/share/makecldef.c b/util/ego/share/makecldef.c index a89d30538..2913e26f5 100644 --- a/util/ego/share/makecldef.c +++ b/util/ego/share/makecldef.c @@ -37,14 +37,14 @@ convert(mnemfile,classfile) printf("\tNOCLASS,\tNOCLASS,\n"); /* EM mnemonics start at 1, arrays in C at 0 */ 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" */ if (feof(mnemfile)) break; if (strcmp(def,"#define") != 0) { error("bad mnemonic file, #define expected"); } 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" */ } if (feof(classfile) || strcmp(mnem1,mnem2) != 0) { diff --git a/util/ego/sp/sp.c b/util/ego/sp/sp.c index 051281d7e..0ba323a10 100644 --- a/util/ego/sp/sp.c +++ b/util/ego/sp/sp.c @@ -60,7 +60,7 @@ STATIC void sp_machinit(void *vp) for (;;) { while(getc(f) != '\n'); - fscanf(f,"%s",s); + fscanf(f,"%99s",s); if (strcmp(s,"%%SP") == 0)break; } fscanf(f,"%d",&globl_sp_allowed); diff --git a/util/ego/sr/sr.c b/util/ego/sr/sr.c index e933cb0de..bdfedef01 100644 --- a/util/ego/sr/sr.c +++ b/util/ego/sr/sr.c @@ -61,7 +61,7 @@ void sr_machinit(void *vp) for (;;) { while(getc(f) != '\n'); - fscanf(f,"%s",s); + fscanf(f,"%99s",s); if (strcmp(s,"%%SR") == 0)break; } fscanf(f,"%d",&ovfl_harmful); diff --git a/util/ego/ud/ud.c b/util/ego/ud/ud.c index 087337144..6afcd5c2b 100644 --- a/util/ego/ud/ud.c +++ b/util/ego/ud/ud.c @@ -64,7 +64,7 @@ STATIC void ud_machinit(void *vp) for (;;) { while(getc(f) != '\n'); - fscanf(f,"%s",s); + fscanf(f,"%99s",s); if (strcmp(s,"%%UD") == 0)break; } globl_cond_tab = getcondtab(f); diff --git a/util/int/switch/mkiswitch.c b/util/int/switch/mkiswitch.c index b9676d237..8be3d54a9 100644 --- a/util/int/switch/mkiswitch.c +++ b/util/int/switch/mkiswitch.c @@ -52,7 +52,7 @@ main(argc, argv) } /* Start reading the input file */ - while (fscanf(ifp, "%s %s", mnem, flgs) >= 0) { + while (fscanf(ifp, "%7s %7s", mnem, flgs) >= 0) { int i; char *p; char *base; diff --git a/util/int/switch/mkswitch.c b/util/int/switch/mkswitch.c index 01446bd95..2ada08a3c 100644 --- a/util/int/switch/mkswitch.c +++ b/util/int/switch/mkswitch.c @@ -55,7 +55,7 @@ main(argc, argv) } /* Start reading the input file */ - while (fscanf(ifp, "%s %s", mnem, flgs) >= 0) { + while (fscanf(ifp, "%7s %7s", mnem, flgs) >= 0) { int i; char *p; char *base;