use snprintf() instead of sprintf() to avoid buffer overflows when copying style names
This commit is contained in:
@ -316,8 +316,8 @@ void Update::create_integrate(int narg, char **arg, int trysuffix)
|
||||
|
||||
if (sflag) {
|
||||
char estyle[256];
|
||||
if (sflag == 1) sprintf(estyle,"%s/%s",arg[0],lmp->suffix);
|
||||
else sprintf(estyle,"%s/%s",arg[0],lmp->suffix2);
|
||||
if (sflag == 1) snprintf(estyle,256,"%s/%s",arg[0],lmp->suffix);
|
||||
else snprintf(estyle,256,"%s/%s",arg[0],lmp->suffix2);
|
||||
int n = strlen(estyle) + 1;
|
||||
integrate_style = new char[n];
|
||||
strcpy(integrate_style,estyle);
|
||||
@ -339,7 +339,7 @@ void Update::new_integrate(char *style, int narg, char **arg,
|
||||
if (lmp->suffix) {
|
||||
sflag = 1;
|
||||
char estyle[256];
|
||||
sprintf(estyle,"%s/%s",style,lmp->suffix);
|
||||
snprintf(estyle,256,"%s/%s",style,lmp->suffix);
|
||||
if (integrate_map->find(estyle) != integrate_map->end()) {
|
||||
IntegrateCreator integrate_creator = (*integrate_map)[estyle];
|
||||
integrate = integrate_creator(lmp, narg, arg);
|
||||
@ -350,7 +350,7 @@ void Update::new_integrate(char *style, int narg, char **arg,
|
||||
if (lmp->suffix2) {
|
||||
sflag = 2;
|
||||
char estyle[256];
|
||||
sprintf(estyle,"%s/%s",style,lmp->suffix2);
|
||||
snprintf(estyle,256,"%s/%s",style,lmp->suffix2);
|
||||
if (integrate_map->find(estyle) != integrate_map->end()) {
|
||||
IntegrateCreator integrate_creator = (*integrate_map)[estyle];
|
||||
integrate = integrate_creator(lmp, narg, arg);
|
||||
|
||||
Reference in New Issue
Block a user