more fixes for potential buffer overflows by using snprintf() instead of sprintf()

This commit is contained in:
Axel Kohlmeyer
2018-09-06 11:32:44 -04:00
parent 9c27548a5c
commit db510af582
10 changed files with 213 additions and 226 deletions

View File

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

View File

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

View File

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

View File

@ -62,7 +62,7 @@ FixReaxCBonds::FixReaxCBonds(LAMMPS *lmp, int narg, char **arg) :
if (suffix && strcmp(suffix,".gz") == 0) {
#ifdef LAMMPS_GZIP
char gzip[128];
sprintf(gzip,"gzip -6 > %s",arg[4]);
snprintf(gzip,128,"gzip -6 > %s",arg[4]);
#ifdef _WIN32
fp = _popen(gzip,"wb");
#else
@ -75,7 +75,7 @@ FixReaxCBonds::FixReaxCBonds(LAMMPS *lmp, int narg, char **arg) :
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open fix reax/c/bonds file %s",arg[4]);
snprintf(str,128,"Cannot open fix reax/c/bonds file %s",arg[4]);
error->one(FLERR,str);
}
}

View File

@ -98,9 +98,7 @@ FixReaxCSpecies::FixReaxCSpecies(LAMMPS *lmp, int narg, char **arg) :
}
if (me == 0 && rene_flag) {
char str[128];
sprintf(str,"Resetting reneighboring criteria for fix reax/c/species");
error->warning(FLERR,str);
error->warning(FLERR,"Resetting reneighboring criteria for fix reax/c/species");
}
tmparg = NULL;
@ -127,7 +125,7 @@ FixReaxCSpecies::FixReaxCSpecies(LAMMPS *lmp, int narg, char **arg) :
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open fix reax/c/species file %s",arg[6]);
snprintf(str,128,"Cannot open fix reax/c/species file %s",arg[6]);
error->one(FLERR,str);
}
}

View File

@ -301,7 +301,7 @@ void PairReaxC::coeff( int nargs, char **args )
Read_Force_Field(fp, &(system->reax_param), control);
else {
char str[128];
sprintf(str,"Cannot open ReaxFF potential file %s",file);
snprintf(str,128,"Cannot open ReaxFF potential file %s",file);
error->all(FLERR,str);
}

View File

@ -86,7 +86,7 @@ FixSMDIntegrateTlsph::FixSMDIntegrateTlsph(LAMMPS *lmp, int narg, char **arg) :
}
} else {
char msg[128];
sprintf(msg, "Illegal keyword for smd/integrate_tlsph: %s\n", arg[iarg]);
snprintf(msg,128, "Illegal keyword for smd/integrate_tlsph: %s\n", arg[iarg]);
error->all(FLERR, msg);
}

View File

@ -119,7 +119,7 @@ FixSMDIntegrateUlsph::FixSMDIntegrateUlsph(LAMMPS *lmp, int narg, char **arg) :
}
} else {
char msg[128];
sprintf(msg, "Illegal keyword for smd/integrate_ulsph: %s\n", arg[iarg]);
snprintf(msg,128, "Illegal keyword for smd/integrate_ulsph: %s\n", arg[iarg]);
error->all(FLERR, msg);
}

View File

@ -200,7 +200,7 @@ FixSMDMoveTriSurf::FixSMDMoveTriSurf(LAMMPS *lmp, int narg, char **arg) :
} else {
char msg[128];
sprintf(msg, "Illegal keyword for fix smd/move_tri_surf: %s\n", arg[iarg]);
snprintf(msg,128, "Illegal keyword for fix smd/move_tri_surf: %s\n", arg[iarg]);
error->all(FLERR, msg);
}

View File

@ -238,7 +238,7 @@ void FixSMDWallSurface::read_triangles(int pass) {
FILE *fp = fopen(filename, "r");
if (fp == NULL) {
char str[128];
sprintf(str, "Cannot open file %s", filename);
snprintf(str,128, "Cannot open file %s", filename);
error->one(FLERR, str);
}
@ -261,7 +261,6 @@ void FixSMDWallSurface::read_triangles(int pass) {
}
}
char str[128];
char line[256];
char *retpointer;
char **values;
@ -270,14 +269,12 @@ void FixSMDWallSurface::read_triangles(int pass) {
// read STL solid name
retpointer = fgets(line, sizeof(line), fp);
if (retpointer == NULL) {
sprintf(str, "error reading number of triangle pairs");
error->one(FLERR, str);
error->one(FLERR,"error reading number of triangle pairs");
}
nwords = count_words(line);
if (nwords < 1) {
sprintf(str, "first line of file is incorrect");
error->one(FLERR, str);
error->one(FLERR,"first line of file is incorrect");
}
// values = new char*[nwords];
@ -327,14 +324,12 @@ void FixSMDWallSurface::read_triangles(int pass) {
// read outer loop line
retpointer = fgets(line, sizeof(line), fp);
if (retpointer == NULL) {
sprintf(str, "error reading outer loop");
error->one(FLERR, str);
error->one(FLERR, "error reading outer loop");
}
nwords = count_words(line);
if (nwords != 2) {
sprintf(str, "error reading outer loop");
error->one(FLERR, str);
error->one(FLERR,"error reading outer loop");
}
// read vertex lines
@ -342,14 +337,12 @@ void FixSMDWallSurface::read_triangles(int pass) {
for (int k = 0; k < 3; k++) {
retpointer = fgets(line, sizeof(line), fp);
if (retpointer == NULL) {
sprintf(str, "error reading vertex line");
error->one(FLERR, str);
error->one(FLERR,"error reading vertex line");
}
nwords = count_words(line);
if (nwords != 4) {
sprintf(str, "error reading vertex line");
error->one(FLERR, str);
error->one(FLERR,"error reading vertex line");
}
values = new char*[nwords];
@ -373,27 +366,23 @@ void FixSMDWallSurface::read_triangles(int pass) {
// read end loop line
retpointer = fgets(line, sizeof(line), fp);
if (retpointer == NULL) {
sprintf(str, "error reading endloop");
error->one(FLERR, str);
error->one(FLERR, "error reading endloop");
}
nwords = count_words(line);
if (nwords != 1) {
sprintf(str, "error reading endloop");
error->one(FLERR, str);
error->one(FLERR,"error reading endloop");
}
// read end facet line
retpointer = fgets(line, sizeof(line), fp);
if (retpointer == NULL) {
sprintf(str, "error reading endfacet");
error->one(FLERR, str);
error->one(FLERR,"error reading endfacet");
}
nwords = count_words(line);
if (nwords != 1) {
sprintf(str, "error reading endfacet");
error->one(FLERR, str);
error->one(FLERR,"error reading endfacet");
}
// now we have a normal and three vertices ... proceed with adding triangle