Skip to content

Commit 3f88486

Browse files
Mart-Bogdansvigerske
authored andcommitted
Fix possible buffer overflow in ClpSimplexOther
1 parent 28cb4ac commit 3f88486

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

Clp/src/ClpSimplexOther.cpp

+21-21
Original file line numberDiff line numberDiff line change
@@ -2135,7 +2135,7 @@ int ClpSimplexOther::parametrics(double startingTheta, double &endingTheta, doub
21352135
}
21362136
if (maxTheta < endingTheta) {
21372137
char line[100];
2138-
sprintf(line, "Crossover considerations reduce ending theta from %g to %g\n",
2138+
snprintf(line, sizeof(line), "Crossover considerations reduce ending theta from %g to %g\n",
21392139
endingTheta, maxTheta);
21402140
handler_->message(CLP_GENERAL, messages_)
21412141
<< line << CoinMessageEol;
@@ -2247,7 +2247,7 @@ int ClpSimplexOther::parametrics(double startingTheta, double &endingTheta, doub
22472247
copyModel.dual();
22482248
if (copyModel.problemStatus()) {
22492249
char line[100];
2250-
sprintf(line, "Can not get to theta of %g\n", startingTheta);
2250+
snprintf(line, sizeof(line), "Can not get to theta of %g\n", startingTheta);
22512251
handler_->message(CLP_GENERAL, messages_)
22522252
<< line << CoinMessageEol;
22532253
canTryQuick = false; // do slowly to get exact amount
@@ -2272,7 +2272,7 @@ int ClpSimplexOther::parametrics(double startingTheta, double &endingTheta, doub
22722272
}
22732273
perturbation_ = savePerturbation;
22742274
char line[100];
2275-
sprintf(line, "Ending theta %g\n", endingTheta);
2275+
snprintf(line, sizeof(line), "Ending theta %g\n", endingTheta);
22762276
handler_->message(CLP_GENERAL, messages_)
22772277
<< line << CoinMessageEol;
22782278
return problemStatus_;
@@ -2291,8 +2291,8 @@ int ClpSimplexOther::parametrics(const char *dataFile)
22912291
return -2;
22922292
}
22932293

2294-
if (!fgets(line, 200, fp)) {
2295-
sprintf(line, "Empty parametrics file %s?", dataFile);
2294+
if (!fgets(line, sizeof(line), fp)) {
2295+
snprintf(line, sizeof(line), "Empty parametrics file %s?", dataFile);
22962296
handler_->message(CLP_GENERAL, messages_)
22972297
<< line << CoinMessageEol;
22982298
fclose(fp);
@@ -2369,14 +2369,14 @@ int ClpSimplexOther::parametrics(const char *dataFile)
23692369
intervalTheta = 0.0;
23702370
if (!good) {
23712371
char line2[300];
2372-
sprintf(line2, "Odd first line %s on file %s?", line, dataFile);
2372+
snprintf(line2, sizeof(line2), "Odd first line %s on file %s?", line, dataFile);
23732373
handler_->message(CLP_GENERAL, messages_)
23742374
<< line2 << CoinMessageEol;
23752375
fclose(fp);
23762376
return -2;
23772377
}
2378-
if (!fgets(line, 200, fp)) {
2379-
sprintf(line, "Not enough records on parametrics file %s?", dataFile);
2378+
if (!fgets(line, sizeof(line), fp)) {
2379+
snprintf(line, sizeof(line), "Not enough records on parametrics file %s?", dataFile);
23802380
handler_->message(CLP_GENERAL, messages_)
23812381
<< line << CoinMessageEol;
23822382
fclose(fp);
@@ -2460,7 +2460,7 @@ int ClpSimplexOther::parametrics(const char *dataFile)
24602460
int nLine = 0;
24612461
//int nBadLine = 0;
24622462
int nBadName = 0;
2463-
while (fgets(line, 200, fp)) {
2463+
while (fgets(line, sizeof(line), fp)) {
24642464
if (!strncmp(line, "ENDATA", 6) || !strncmp(line, "COLUMN", 6))
24652465
break;
24662466
nLine++;
@@ -2537,11 +2537,11 @@ int ClpSimplexOther::parametrics(const char *dataFile)
25372537
strcpy(saveLine, line);
25382538
}
25392539
}
2540-
sprintf(line, "%d Row fields and %d records", nAcross, nLine);
2540+
snprintf(line, sizeof(line), "%d Row fields and %d records", nAcross, nLine);
25412541
handler_->message(CLP_GENERAL, messages_)
25422542
<< line << CoinMessageEol;
25432543
if (nBadName) {
2544-
sprintf(line, " ** %d records did not match on name/sequence, first bad %s", nBadName, saveLine);
2544+
snprintf(line, sizeof(line), " ** %d records did not match on name/sequence, first bad %s", nBadName, saveLine);
25452545
handler_->message(CLP_GENERAL, messages_)
25462546
<< line << CoinMessageEol;
25472547
returnCode = -1;
@@ -2552,16 +2552,16 @@ int ClpSimplexOther::parametrics(const char *dataFile)
25522552
}
25532553
delete[] rowNames;
25542554
} else {
2555-
sprintf(line, "Duplicate or unknown keyword - or name/number fields wrong");
2555+
snprintf(line, sizeof(line), "Duplicate or unknown keyword - or name/number fields wrong");
25562556
handler_->message(CLP_GENERAL, messages_)
25572557
<< line << CoinMessageEol;
25582558
returnCode = -1;
25592559
good = false;
25602560
}
25612561
}
25622562
if (good && (!strncmp(line, "COLUMN", 6) || !strncmp(line, "column", 6))) {
2563-
if (!fgets(line, 200, fp)) {
2564-
sprintf(line, "Not enough records on parametrics file %s after COLUMNS?", dataFile);
2563+
if (!fgets(line, sizeof(line), fp)) {
2564+
snprintf(line, sizeof(line), "Not enough records on parametrics file %s after COLUMNS?", dataFile);
25652565
handler_->message(CLP_GENERAL, messages_)
25662566
<< line << CoinMessageEol;
25672567
fclose(fp);
@@ -2632,7 +2632,7 @@ int ClpSimplexOther::parametrics(const char *dataFile)
26322632
int nLine = 0;
26332633
//int nBadLine = 0;
26342634
int nBadName = 0;
2635-
while (fgets(line, 200, fp)) {
2635+
while (fgets(line, sizeof(line), fp)) {
26362636
if (!strncmp(line, "ENDATA", 6))
26372637
break;
26382638
nLine++;
@@ -2711,11 +2711,11 @@ int ClpSimplexOther::parametrics(const char *dataFile)
27112711
strcpy(saveLine, line);
27122712
}
27132713
}
2714-
sprintf(line, "%d Column fields and %d records", nAcross, nLine);
2714+
snprintf(line, sizeof(line), "%d Column fields and %d records", nAcross, nLine);
27152715
handler_->message(CLP_GENERAL, messages_)
27162716
<< line << CoinMessageEol;
27172717
if (nBadName) {
2718-
sprintf(line, " ** %d records did not match on name/sequence, first bad %s", nBadName, saveLine);
2718+
snprintf(line, sizeof(line), " ** %d records did not match on name/sequence, first bad %s", nBadName, saveLine);
27192719
handler_->message(CLP_GENERAL, messages_)
27202720
<< line << CoinMessageEol;
27212721
returnCode = -1;
@@ -2726,7 +2726,7 @@ int ClpSimplexOther::parametrics(const char *dataFile)
27262726
}
27272727
delete[] columnNames;
27282728
} else {
2729-
sprintf(line, "Duplicate or unknown keyword - or name/number fields wrong");
2729+
snprintf(line, sizeof(line), "Duplicate or unknown keyword - or name/number fields wrong");
27302730
handler_->message(CLP_GENERAL, messages_)
27312731
<< line << CoinMessageEol;
27322732
returnCode = -1;
@@ -3282,7 +3282,7 @@ int ClpSimplexOther::parametrics(double startingTheta, double &endingTheta,
32823282
delete rowArray_[5];
32833283
rowArray_[5] = NULL;
32843284
char line[100];
3285-
sprintf(line, "Ending theta %g\n", endingTheta);
3285+
snprintf(line, sizeof(line), "Ending theta %g\n", endingTheta);
32863286
handler_->message(CLP_GENERAL, messages_)
32873287
<< line << CoinMessageEol;
32883288
return problemStatus_;
@@ -5932,7 +5932,7 @@ ClpSimplexOther::gubVersion(int *whichRows, int *whichColumns,
59325932
}
59335933
}
59345934
if (!numberNormal) {
5935-
sprintf(message, "Putting back one gub row to make non-empty");
5935+
snprintf(message, sizeof(message), "Putting back one gub row to make non-empty");
59365936
handler_->message(CLP_GENERAL2, messages_)
59375937
<< message << CoinMessageEol;
59385938
rowIsGub[smallestGubRow] = -1;
@@ -6146,7 +6146,7 @@ ClpSimplexOther::gubVersion(int *whichRows, int *whichColumns,
61466146
}
61476147
}
61486148
}
6149-
sprintf(message, "** Before adding matrix there are %d rows and %d columns",
6149+
snprintf(message, sizeof(message), "** Before adding matrix there are %d rows and %d columns",
61506150
model2->numberRows(), model2->numberColumns());
61516151
handler_->message(CLP_GENERAL2, messages_)
61526152
<< message << CoinMessageEol;

0 commit comments

Comments
 (0)