more buffer overflow avoiding through using snprintf()

This commit is contained in:
Axel Kohlmeyer
2018-09-06 09:57:43 -04:00
parent fbc1c1cfdd
commit 4d52cb9245
9 changed files with 26 additions and 26 deletions

View File

@ -528,7 +528,7 @@ void Variable::set(int narg, char **arg)
for (int i = 0; i < n-1; i++)
if (!isalnum(names[nvar][i]) && names[nvar][i] != '_') {
char errmsg[128];
sprintf(errmsg,"Variable name '%s' must have only alphanumeric "
snprintf(errmsg,128,"Variable name '%s' must have only alphanumeric "
"characters or underscore",names[nvar]);
error->all(FLERR,errmsg);
}
@ -586,7 +586,7 @@ int Variable::next(int narg, char **arg)
ivar = find(arg[iarg]);
if (ivar < 0) {
char errmsg[128];
sprintf(errmsg,"Invalid variable '%s' in next command",arg[iarg]);
snprintf(errmsg,128,"Invalid variable '%s' in next command",arg[iarg]);
error->all(FLERR,errmsg);
}
if (style[ivar] == ULOOP && style[find(arg[0])] == UNIVERSE) continue;
@ -886,7 +886,7 @@ char *Variable::retrieve(char *name)
int ifunc = python->variable_match(data[ivar][0],name,0);
if (ifunc < 0) {
char errmsg[128];
sprintf(errmsg,"Python variable '%s' does not match Python function",name);
snprintf(errmsg,128,"Python variable '%s' does not match Python function",name);
error->all(FLERR,errmsg);
}
python->invoke_function(ifunc,data[ivar][1]);
@ -1597,7 +1597,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
int ifix = modify->find_fix(word+2);
if (ifix < 0) {
char msg[128];
sprintf(msg,"Invalid fix ID '%s' in variable formula",word+2);
snprintf(msg,128,"Invalid fix ID '%s' in variable formula",word+2);
print_var_error(FLERR,msg,ivar);
}
Fix *fix = modify->fix[ifix];
@ -2032,8 +2032,8 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
argstack,nargstack,ivar));
else {
char msg[128];
sprintf(msg,"Invalid math/group/special function '%s()'"
"in variable formula", word);
snprintf(msg,128,"Invalid math/group/special function '%s()'"
"in variable formula", word);
print_var_error(FLERR,msg,ivar);
}
delete [] contents;
@ -2092,7 +2092,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
int flag = output->thermo->evaluate_keyword(word,&value1);
if (flag) {
char msg[128];
sprintf(msg,"Invalid thermo keyword '%s' in variable formula",word);
snprintf(msg,128,"Invalid thermo keyword '%s' in variable formula",word);
print_var_error(FLERR,msg,ivar);
}
if (tree) {
@ -4013,7 +4013,7 @@ int Variable::special_function(char *word, char *contents, Tree **tree,
int icompute = modify->find_compute(&args[0][2]);
if (icompute < 0) {
char msg[128];
sprintf(msg,"Invalid compute ID '%s' in variable formula",word+2);
snprintf(msg,128,"Invalid compute ID '%s' in variable formula",word+2);
print_var_error(FLERR,msg,ivar);
}
compute = modify->compute[icompute];
@ -4656,7 +4656,7 @@ void Variable::print_var_error(const char *srcfile, int lineno,
if ((ivar >= 0) && (ivar < nvar)) {
char msg[128];
sprintf(msg,"Variable %s: %s",names[ivar],errmsg);
snprintf(msg,128,"Variable %s: %s",names[ivar],errmsg);
error->all(srcfile,lineno,msg);
} else error->all(srcfile,lineno,errmsg);
}
@ -4944,7 +4944,7 @@ VarReader::VarReader(LAMMPS *lmp, char *name, char *file, int flag) :
fp = fopen(file,"r");
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open file variable file %s",file);
snprintf(str,128,"Cannot open file variable file %s",file);
error->one(FLERR,str);
}
}