add check that allows only %f and %g conversions in variable format strings

This commit is contained in:
Axel Kohlmeyer
2019-05-30 14:46:07 -04:00
parent 8dcd6fc48c
commit 1a5c3c6dcb
5 changed files with 24 additions and 0 deletions

View File

@ -38,6 +38,7 @@
#include "memory.h"
#include "info.h"
#include "error.h"
#include "utils.h"
using namespace LAMMPS_NS;
using namespace MathConst;
@ -383,6 +384,8 @@ void Variable::set(int narg, char **arg)
num[nvar] = 3;
which[nvar] = 0;
pad[nvar] = 0;
if (!utils::strmatch(arg[2],"%[0-9 ]*\\.[0-9]+[fg]"))
error->all(FLERR,"Incorrect conversion in format string");
data[nvar] = new char*[num[nvar]];
copy(2,&arg[2],data[nvar]);
data[nvar][2] = new char[VALUELENGTH];