Skip to content

Commit 8596ee3

Browse files
Mart-Bogdansvigerske
authored andcommitted
Fix possible buffer overflow in ClpSimplexOther
1 parent 327fcdb commit 8596ee3

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

src/ClpSimplexOther.cpp

+23-22
Original file line numberDiff line numberDiff line change
@@ -2645,7 +2645,7 @@ int ClpSimplexOther::parametrics(double startingTheta, double &endingTheta, doub
26452645
}
26462646
if (maxTheta < endingTheta) {
26472647
char line[100];
2648-
sprintf(line, "Crossover considerations reduce ending theta from %g to %g\n",
2648+
snprintf(line, sizeof(line), "Crossover considerations reduce ending theta from %g to %g\n",
26492649
endingTheta, maxTheta);
26502650
handler_->message(CLP_GENERAL, messages_)
26512651
<< line << CoinMessageEol;
@@ -2757,7 +2757,7 @@ int ClpSimplexOther::parametrics(double startingTheta, double &endingTheta, doub
27572757
copyModel.dual();
27582758
if (copyModel.problemStatus()) {
27592759
char line[100];
2760-
sprintf(line, "Can not get to theta of %g\n", startingTheta);
2760+
snprintf(line, sizeof(line), "Can not get to theta of %g\n", startingTheta);
27612761
handler_->message(CLP_GENERAL, messages_)
27622762
<< line << CoinMessageEol;
27632763
canTryQuick = false; // do slowly to get exact amount
@@ -2782,7 +2782,7 @@ int ClpSimplexOther::parametrics(double startingTheta, double &endingTheta, doub
27822782
}
27832783
perturbation_ = savePerturbation;
27842784
char line[100];
2785-
sprintf(line, "Ending theta %g\n", endingTheta);
2785+
snprintf(line, sizeof(line), "Ending theta %g\n", endingTheta);
27862786
handler_->message(CLP_GENERAL, messages_)
27872787
<< line << CoinMessageEol;
27882788
return problemStatus_;
@@ -2801,8 +2801,8 @@ int ClpSimplexOther::parametrics(const char *dataFile)
28012801
return -2;
28022802
}
28032803

2804-
if (!fgets(line, 200, fp)) {
2805-
sprintf(line, "Empty parametrics file %s?", dataFile);
2804+
if (!fgets(line, sizeof(line), fp)) {
2805+
snprintf(line, sizeof(line), "Empty parametrics file %s?", dataFile);
28062806
handler_->message(CLP_GENERAL, messages_)
28072807
<< line << CoinMessageEol;
28082808
fclose(fp);
@@ -2878,14 +2878,15 @@ int ClpSimplexOther::parametrics(const char *dataFile)
28782878
if (intervalTheta >= endTheta)
28792879
intervalTheta = 0.0;
28802880
if (!good) {
2881-
sprintf(line, "Odd first line %s on file %s?", line, dataFile);
2881+
char line2[300];
2882+
snprintf(line2, sizeof(line2), "Odd first line %s on file %s?", line, dataFile);
28822883
handler_->message(CLP_GENERAL, messages_)
2883-
<< line << CoinMessageEol;
2884+
<< line2 << CoinMessageEol;
28842885
fclose(fp);
28852886
return -2;
28862887
}
2887-
if (!fgets(line, 200, fp)) {
2888-
sprintf(line, "Not enough records on parametrics file %s?", dataFile);
2888+
if (!fgets(line, sizeof(line), fp)) {
2889+
snprintf(line, sizeof(line), "Not enough records on parametrics file %s?", dataFile);
28892890
handler_->message(CLP_GENERAL, messages_)
28902891
<< line << CoinMessageEol;
28912892
fclose(fp);
@@ -2969,7 +2970,7 @@ int ClpSimplexOther::parametrics(const char *dataFile)
29692970
int nLine = 0;
29702971
//int nBadLine = 0;
29712972
int nBadName = 0;
2972-
while (fgets(line, 200, fp)) {
2973+
while (fgets(line, sizeof(line), fp)) {
29732974
if (!strncmp(line, "ENDATA", 6) || !strncmp(line, "COLUMN", 6))
29742975
break;
29752976
nLine++;
@@ -3046,11 +3047,11 @@ int ClpSimplexOther::parametrics(const char *dataFile)
30463047
strcpy(saveLine, line);
30473048
}
30483049
}
3049-
sprintf(line, "%d Row fields and %d records", nAcross, nLine);
3050+
snprintf(line, sizeof(line), "%d Row fields and %d records", nAcross, nLine);
30503051
handler_->message(CLP_GENERAL, messages_)
30513052
<< line << CoinMessageEol;
30523053
if (nBadName) {
3053-
sprintf(line, " ** %d records did not match on name/sequence, first bad %s", nBadName, saveLine);
3054+
snprintf(line, sizeof(line), " ** %d records did not match on name/sequence, first bad %s", nBadName, saveLine);
30543055
handler_->message(CLP_GENERAL, messages_)
30553056
<< line << CoinMessageEol;
30563057
returnCode = -1;
@@ -3061,16 +3062,16 @@ int ClpSimplexOther::parametrics(const char *dataFile)
30613062
}
30623063
delete[] rowNames;
30633064
} else {
3064-
sprintf(line, "Duplicate or unknown keyword - or name/number fields wrong");
3065+
snprintf(line, sizeof(line), "Duplicate or unknown keyword - or name/number fields wrong");
30653066
handler_->message(CLP_GENERAL, messages_)
30663067
<< line << CoinMessageEol;
30673068
returnCode = -1;
30683069
good = false;
30693070
}
30703071
}
30713072
if (good && (!strncmp(line, "COLUMN", 6) || !strncmp(line, "column", 6))) {
3072-
if (!fgets(line, 200, fp)) {
3073-
sprintf(line, "Not enough records on parametrics file %s after COLUMNS?", dataFile);
3073+
if (!fgets(line, sizeof(line), fp)) {
3074+
snprintf(line, sizeof(line), "Not enough records on parametrics file %s after COLUMNS?", dataFile);
30743075
handler_->message(CLP_GENERAL, messages_)
30753076
<< line << CoinMessageEol;
30763077
fclose(fp);
@@ -3141,7 +3142,7 @@ int ClpSimplexOther::parametrics(const char *dataFile)
31413142
int nLine = 0;
31423143
//int nBadLine = 0;
31433144
int nBadName = 0;
3144-
while (fgets(line, 200, fp)) {
3145+
while (fgets(line, sizeof(line), fp)) {
31453146
if (!strncmp(line, "ENDATA", 6))
31463147
break;
31473148
nLine++;
@@ -3220,11 +3221,11 @@ int ClpSimplexOther::parametrics(const char *dataFile)
32203221
strcpy(saveLine, line);
32213222
}
32223223
}
3223-
sprintf(line, "%d Column fields and %d records", nAcross, nLine);
3224+
snprintf(line, sizeof(line), "%d Column fields and %d records", nAcross, nLine);
32243225
handler_->message(CLP_GENERAL, messages_)
32253226
<< line << CoinMessageEol;
32263227
if (nBadName) {
3227-
sprintf(line, " ** %d records did not match on name/sequence, first bad %s", nBadName, saveLine);
3228+
snprintf(line, sizeof(line), " ** %d records did not match on name/sequence, first bad %s", nBadName, saveLine);
32283229
handler_->message(CLP_GENERAL, messages_)
32293230
<< line << CoinMessageEol;
32303231
returnCode = -1;
@@ -3235,7 +3236,7 @@ int ClpSimplexOther::parametrics(const char *dataFile)
32353236
}
32363237
delete[] columnNames;
32373238
} else {
3238-
sprintf(line, "Duplicate or unknown keyword - or name/number fields wrong");
3239+
snprintf(line, sizeof(line), "Duplicate or unknown keyword - or name/number fields wrong");
32393240
handler_->message(CLP_GENERAL, messages_)
32403241
<< line << CoinMessageEol;
32413242
returnCode = -1;
@@ -3791,7 +3792,7 @@ int ClpSimplexOther::parametrics(double startingTheta, double &endingTheta,
37913792
delete rowArray_[5];
37923793
rowArray_[5] = NULL;
37933794
char line[100];
3794-
sprintf(line, "Ending theta %g\n", endingTheta);
3795+
snprintf(line, sizeof(line), "Ending theta %g\n", endingTheta);
37953796
handler_->message(CLP_GENERAL, messages_)
37963797
<< line << CoinMessageEol;
37973798
return problemStatus_;
@@ -6444,7 +6445,7 @@ ClpSimplexOther::gubVersion(int *whichRows, int *whichColumns,
64446445
}
64456446
}
64466447
if (!numberNormal) {
6447-
sprintf(message, "Putting back one gub row to make non-empty");
6448+
snprintf(message, sizeof(message), "Putting back one gub row to make non-empty");
64486449
handler_->message(CLP_GENERAL2, messages_)
64496450
<< message << CoinMessageEol;
64506451
rowIsGub[smallestGubRow] = -1;
@@ -6658,7 +6659,7 @@ ClpSimplexOther::gubVersion(int *whichRows, int *whichColumns,
66586659
}
66596660
}
66606661
}
6661-
sprintf(message, "** Before adding matrix there are %d rows and %d columns",
6662+
snprintf(message, sizeof(message), "** Before adding matrix there are %d rows and %d columns",
66626663
model2->numberRows(), model2->numberColumns());
66636664
handler_->message(CLP_GENERAL2, messages_)
66646665
<< message << CoinMessageEol;

0 commit comments

Comments
 (0)