fix bond/react buffer overflow: must not use sprintf to write to char variable

This commit is contained in:
Axel Kohlmeyer
2020-12-30 09:54:46 -05:00
parent 51a20175c9
commit b08582de69

View File

@ -1966,12 +1966,11 @@ int FixBondReact::check_constraints()
} }
if (nconstraints[rxnID] > 0) { if (nconstraints[rxnID] > 0) {
char evalstr[MAXLINE],*ptr,valstr; char evalstr[MAXLINE],*ptr;
strcpy(evalstr,constraintstr[rxnID]); strcpy(evalstr,constraintstr[rxnID]);
for (int i = 0; i < nconstraints[rxnID]; i++) { for (int i = 0; i < nconstraints[rxnID]; i++) {
sprintf(&valstr,"%d", satisfied[i]);
ptr = strchr(evalstr,'C'); ptr = strchr(evalstr,'C');
*ptr = valstr; *ptr = satisfied[i] ? '1' : '0';
} }
double verdict = input->variable->evaluate_boolean(evalstr); double verdict = input->variable->evaluate_boolean(evalstr);
if (verdict == 0.0) return 0; if (verdict == 0.0) return 0;