Commit 4d52cb92 authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

more buffer overflow avoiding through using snprintf()

parent fbc1c1cf
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -362,7 +362,7 @@ void PairTable::read_table(Table *tb, char *file, char *keyword)
  FILE *fp = force->open_potential(file);
  if (fp == NULL) {
    char str[128];
    sprintf(str,"Cannot open file %s",file);
    snprintf(str,128,"Cannot open file %s",file);
    error->one(FLERR,str);
  }

+3 −3
Original line number Diff line number Diff line
@@ -706,7 +706,7 @@ void ReadData::command(int narg, char **arg)

      } else {
        char str[128];
        sprintf(str,"Unknown identifier in data file: %s",keyword);
        snprintf(str,128,"Unknown identifier in data file: %s",keyword);
        error->all(FLERR,str);
      }

@@ -1919,7 +1919,7 @@ void ReadData::open(char *file)
  else {
#ifdef LAMMPS_GZIP
    char gunzip[128];
    sprintf(gunzip,"gzip -c -d %s",file);
    snprintf(gunzip,128,"gzip -c -d %s",file);

#ifdef _WIN32
    fp = _popen(gunzip,"rb");
@@ -1934,7 +1934,7 @@ void ReadData::open(char *file)

  if (fp == NULL) {
    char str[128];
    sprintf(str,"Cannot open file %s",file);
    snprintf(str,128,"Cannot open file %s",file);
    error->one(FLERR,str);
  }
}
+3 −3
Original line number Diff line number Diff line
@@ -138,7 +138,7 @@ void ReadRestart::command(int narg, char **arg)
    fp = fopen(hfile,"rb");
    if (fp == NULL) {
      char str[128];
      sprintf(str,"Cannot open restart file %s",hfile);
      snprintf(str,128,"Cannot open restart file %s",hfile);
      error->one(FLERR,str);
    }
    if (multiproc) delete [] hfile;
@@ -297,7 +297,7 @@ void ReadRestart::command(int narg, char **arg)
      fp = fopen(procfile,"rb");
      if (fp == NULL) {
        char str[128];
        sprintf(str,"Cannot open restart file %s",procfile);
        snprintf(str,128,"Cannot open restart file %s",procfile);
        error->one(FLERR,str);
      }

@@ -369,7 +369,7 @@ void ReadRestart::command(int narg, char **arg)
      fp = fopen(procfile,"rb");
      if (fp == NULL) {
        char str[128];
        sprintf(str,"Cannot open restart file %s",procfile);
        snprintf(str,128,"Cannot open restart file %s",procfile);
        error->one(FLERR,str);
      }
      delete [] procfile;
+2 −2
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ void Reader::open_file(const char *file)
  else {
#ifdef LAMMPS_GZIP
    char gunzip[1024];
    sprintf(gunzip,"gzip -c -d %s",file);
    snprintf(gunzip,1024,"gzip -c -d %s",file);

#ifdef _WIN32
    fp = _popen(gunzip,"rb");
@@ -56,7 +56,7 @@ void Reader::open_file(const char *file)

  if (fp == NULL) {
    char str[128];
    sprintf(str,"Cannot open file %s",file);
    snprintf(str,128,"Cannot open file %s",file);
    error->one(FLERR,str);
  }
}
+2 −2
Original line number Diff line number Diff line
@@ -204,7 +204,7 @@ void Universe::add_world(char *str)

    if (!valid) {
      char msg[128];
      sprintf(msg,"Invalid partition string '%s'",str);
      snprintf(msg,128,"Invalid partition string '%s'",str);
      error->universe_all(FLERR,msg);
    }
  } else nper = nprocs;
@@ -269,7 +269,7 @@ char *date2num(const char *version)
    year = atoi(version);
  }

  char *ver = new char[10];
  char *ver = new char[64];
  sprintf(ver,"%04d%02d%02d", year % 10000, month, day % 100);

  return ver;
Loading