Skip to content

Commit

Permalink
Fix possible buffer overflow in ClpSimplexOther::parametrics
Browse files Browse the repository at this point in the history
  • Loading branch information
Bogdan Mart committed Oct 10, 2023
1 parent 914e0af commit 07ab323
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions Clp/src/ClpSimplexOther.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2283,8 +2283,8 @@ int ClpSimplexOther::parametrics(const char *dataFile)
return -2;
}

if (!fgets(line, 200, fp)) {
sprintf(line, "Empty parametrics file %s?", dataFile);
if (!fgets(line, sizeof(line), fp)) {
snprintf(line, sizeof(line), "Empty parametrics file %s?", dataFile);
handler_->message(CLP_GENERAL, messages_)
<< line << CoinMessageEol;
fclose(fp);
Expand Down Expand Up @@ -2360,14 +2360,14 @@ int ClpSimplexOther::parametrics(const char *dataFile)
if (intervalTheta >= endTheta)
intervalTheta = 0.0;
if (!good) {
sprintf(line, "Odd first line %s on file %s?", line, dataFile);
snprintf(line, sizeof(line), "Odd first line %s on file %s?", line, dataFile);
handler_->message(CLP_GENERAL, messages_)
<< line << CoinMessageEol;
fclose(fp);
return -2;
}
if (!fgets(line, 200, fp)) {
sprintf(line, "Not enough records on parametrics file %s?", dataFile);
if (!fgets(line, sizeof(line), fp)) {
snprintf(line, sizeof(line), "Not enough records on parametrics file %s?", dataFile);
handler_->message(CLP_GENERAL, messages_)
<< line << CoinMessageEol;
fclose(fp);
Expand Down Expand Up @@ -2451,7 +2451,7 @@ int ClpSimplexOther::parametrics(const char *dataFile)
int nLine = 0;
int nBadLine = 0;
int nBadName = 0;
while (fgets(line, 200, fp)) {
while (fgets(line, sizeof(line), fp)) {
if (!strncmp(line, "ENDATA", 6) || !strncmp(line, "COLUMN", 6))
break;
nLine++;
Expand Down Expand Up @@ -2532,7 +2532,7 @@ int ClpSimplexOther::parametrics(const char *dataFile)
handler_->message(CLP_GENERAL, messages_)
<< line << CoinMessageEol;
if (nBadName) {
sprintf(line, " ** %d records did not match on name/sequence, first bad %s", nBadName, saveLine);
snprintf(line, sizeof(line), " ** %d records did not match on name/sequence, first bad %s", nBadName, saveLine);
handler_->message(CLP_GENERAL, messages_)
<< line << CoinMessageEol;
returnCode = -1;
Expand All @@ -2543,16 +2543,16 @@ int ClpSimplexOther::parametrics(const char *dataFile)
}
delete[] rowNames;
} else {
sprintf(line, "Duplicate or unknown keyword - or name/number fields wrong");
snprintf(line, sizeof(line), "Duplicate or unknown keyword - or name/number fields wrong");
handler_->message(CLP_GENERAL, messages_)
<< line << CoinMessageEol;
returnCode = -1;
good = false;
}
}
if (good && (!strncmp(line, "COLUMN", 6) || !strncmp(line, "column", 6))) {
if (!fgets(line, 200, fp)) {
sprintf(line, "Not enough records on parametrics file %s after COLUMNS?", dataFile);
if (!fgets(line, sizeof(line), fp)) {
snprintf(line, sizeof(line), "Not enough records on parametrics file %s after COLUMNS?", dataFile);
handler_->message(CLP_GENERAL, messages_)
<< line << CoinMessageEol;
fclose(fp);
Expand Down Expand Up @@ -2623,7 +2623,7 @@ int ClpSimplexOther::parametrics(const char *dataFile)
int nLine = 0;
int nBadLine = 0;
int nBadName = 0;
while (fgets(line, 200, fp)) {
while (fgets(line, sizeof(line), fp)) {
if (!strncmp(line, "ENDATA", 6))
break;
nLine++;
Expand Down Expand Up @@ -2702,11 +2702,11 @@ int ClpSimplexOther::parametrics(const char *dataFile)
strcpy(saveLine, line);
}
}
sprintf(line, "%d Column fields and %d records", nAcross, nLine);
snprintf(line, sizeof(line), "%d Column fields and %d records", nAcross, nLine);
handler_->message(CLP_GENERAL, messages_)
<< line << CoinMessageEol;
if (nBadName) {
sprintf(line, " ** %d records did not match on name/sequence, first bad %s", nBadName, saveLine);
snprintf(line, sizeof(line), " ** %d records did not match on name/sequence, first bad %s", nBadName, saveLine);
handler_->message(CLP_GENERAL, messages_)
<< line << CoinMessageEol;
returnCode = -1;
Expand All @@ -2717,7 +2717,7 @@ int ClpSimplexOther::parametrics(const char *dataFile)
}
delete[] columnNames;
} else {
sprintf(line, "Duplicate or unknown keyword - or name/number fields wrong");
snprintf(line, sizeof(line), "Duplicate or unknown keyword - or name/number fields wrong");
handler_->message(CLP_GENERAL, messages_)
<< line << CoinMessageEol;
returnCode = -1;
Expand Down

0 comments on commit 07ab323

Please sign in to comment.