avoid unsafe strcpy()

This commit is contained in:
Axel Kohlmeyer
2022-04-09 19:01:42 -04:00
parent 4e81adaf8c
commit 07bc76871c
2 changed files with 6 additions and 7 deletions

View File

@ -107,15 +107,14 @@ FixHalt::FixHalt(LAMMPS *lmp, int narg, char **arg) :
} else if (strcmp(arg[iarg],"path") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal fix halt command");
++iarg;
int len = strlen(arg[iarg])+1;
delete[] dlimit_path;
dlimit_path = new char[len];
// strip off quotes, if present
// strip off outer quotes, if present
int len = strlen(arg[iarg])+1;
if ( ((arg[iarg][0] == '"') || (arg[iarg][0] == '\''))
&& (arg[iarg][0] == arg[iarg][len-2])) {
strcpy(dlimit_path,&arg[iarg][1]);
dlimit_path[len-3] = '\0';
} else strcpy(dlimit_path,arg[iarg]);
arg[iarg][len-2] = '\0';
dlimit_path = utils::strdup(arg[iarg]+1);
} else dlimit_path = utils::strdup(arg[iarg]);
++iarg;
} else error->all(FLERR,"Illegal fix halt command");
}

View File

@ -158,7 +158,7 @@ void FixPrint::end_of_step()
modify->clearstep_compute();
strcpy(copy,text);
strncpy(copy,text,maxcopy);
input->substitute(copy,work,maxcopy,maxwork,0);
if (var_print) {