Skip to content

Commit 91c2db7

Browse files
committed
Non happy-path fixes
1 parent 0ba8f90 commit 91c2db7

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

Diff for: ChangeLog

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ Added support for VS2012
120120
Added a simple project for cppcheck
121121
Rendering intent used when creating the transform is now propagated to profile header in cmsTransform2Devicelink. This is because 7.2.15 in spec 4.3
122122
Transform2Devicelink now keeps white point when guessing deviceclass is enabled
123+
Added some checks for non-happy path, mostly failing mallocs
123124

124125
-----------------------
125126
2.5 Maintenance release

Diff for: src/cmsnamed.c

+7-5
Original file line numberDiff line numberDiff line change
@@ -517,8 +517,8 @@ cmsNAMEDCOLORLIST* CMSEXPORT cmsAllocNamedColorList(cmsContext ContextID, cmsUIn
517517
while (v -> Allocated < n)
518518
GrowNamedColorList(v);
519519

520-
strncpy(v ->Prefix, Prefix, sizeof(v ->Prefix));
521-
strncpy(v ->Suffix, Suffix, sizeof(v ->Suffix));
520+
strncpy(v ->Prefix, Prefix, sizeof(v ->Prefix)-1);
521+
strncpy(v ->Suffix, Suffix, sizeof(v ->Suffix)-1);
522522
v->Prefix[32] = v->Suffix[32] = 0;
523523

524524
v -> ColorantCount = ColorantCount;
@@ -577,9 +577,7 @@ cmsBool CMSEXPORT cmsAppendNamedColor(cmsNAMEDCOLORLIST* NamedColorList,
577577

578578
if (Name != NULL) {
579579

580-
strncpy(NamedColorList ->List[NamedColorList ->nColors].Name, Name,
581-
sizeof(NamedColorList ->List[NamedColorList ->nColors].Name));
582-
580+
strncpy(NamedColorList ->List[NamedColorList ->nColors].Name, Name, cmsMAX_PATH-1);
583581
NamedColorList ->List[NamedColorList ->nColors].Name[cmsMAX_PATH-1] = 0;
584582

585583
}
@@ -735,6 +733,10 @@ cmsSEQ* CMSEXPORT cmsAllocProfileSequenceDescription(cmsContext ContextID, cmsUI
735733
Seq -> seq = (cmsPSEQDESC*) _cmsCalloc(ContextID, n, sizeof(cmsPSEQDESC));
736734
Seq -> n = n;
737735

736+
if (Seq -> seq == NULL) {
737+
_cmsFree(ContextID, Seq);
738+
return NULL;
739+
}
738740

739741
for (i=0; i < n; i++) {
740742
Seq -> seq[i].Manufacturer = NULL;

Diff for: src/cmsopt.c

+10
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,16 @@ Curves16Data* CurvesAlloc(cmsContext ContextID, int nCurves, int nElements, cmsT
11791179

11801180
c16->Curves[i] = _cmsCalloc(ContextID, nElements, sizeof(cmsUInt16Number));
11811181

1182+
if (c16->Curves[i] == NULL) {
1183+
1184+
for (j=0; j < i; j++) {
1185+
_cmsFree(ContextID, c16->Curves[j]);
1186+
}
1187+
_cmsFree(ContextID, c16->Curves);
1188+
_cmsFree(ContextID, c16);
1189+
return NULL;
1190+
}
1191+
11821192
if (nElements == 256) {
11831193

11841194
for (j=0; j < nElements; j++) {

0 commit comments

Comments
 (0)