final pass at sprintf() buffer overflow prevention. also fix typo in previous commit

This commit is contained in:
Axel Kohlmeyer
2018-09-06 12:00:04 -04:00
parent db510af582
commit 84657f1531
5 changed files with 7 additions and 9 deletions

View File

@ -549,7 +549,7 @@ void NEB::open(char *file)
else {
#ifdef LAMMPS_GZIP
char gunzip[128];
snprintf(gunz128,ip,"gzip -c -d %s",file);
snprintf(gunzip,128,"gzip -c -d %s",file);
#ifdef _WIN32
fp = _popen(gunzip,"rb");

View File

@ -1684,8 +1684,8 @@ void PairTlsph::coeff(int narg, char **arg) {
} // end energy release rate failure criterion
else {
sprintf(str, "unknown *KEYWORD: %s", arg[ioffset]);
error->all(FLERR, str);
snprintf(str,128,"unknown *KEYWORD: %s", arg[ioffset]);
error->all(FLERR, str);
}
}

View File

@ -1331,8 +1331,8 @@ void PairULSPH::coeff(int narg, char **arg) {
} // end *ARTIFICIAL_STRESS
else {
sprintf(str, "unknown *KEYWORD: %s", arg[ioffset]);
error->all(FLERR, str);
snprintf(str,128, "unknown *KEYWORD: %s", arg[ioffset]);
error->all(FLERR, str);
}
}

View File

@ -399,7 +399,7 @@ void PairSMTBQ::read_file(char *file)
fp = force->open_potential(file);
if ( fp == NULL ) {
char str[128];
sprintf(str,"Cannot open SMTBQ potential file %s",file);
snprintf(str,128,"Cannot open SMTBQ potential file %s",file);
error->one(FLERR,str);
}

View File

@ -90,9 +90,7 @@ void DumpCFGUef::write_header(bigint n)
if (atom->peri_flag) scale = atom->pdscale;
else if (unwrapflag == 1) scale = UNWRAPEXPAND;
char str[64];
sprintf(str,"Number of particles = %s\n",BIGINT_FORMAT);
fprintf(fp,str,n);
fprintf(fp,"Number of particles = " BIGINT_FORMAT "\n",n);
fprintf(fp,"A = %g Angstrom (basic length-scale)\n",scale);
// in box[][] columns are cell edges
// in H0, rows are cell edges