summaryrefslogtreecommitdiff
path: root/src/cmscgats.c
diff options
context:
space:
mode:
authorMarti Maria <marti.maria@littlecms.com>2021-01-18 16:23:27 +0100
committerMarti Maria <marti.maria@littlecms.com>2021-01-18 16:23:27 +0100
commitcfce6b9fa02f1a2ba8dfb6d27cd20d9934cd3cdb (patch)
tree3add41324cbdeebbe1c00dbd13e3d28cba2af8c9 /src/cmscgats.c
parent8154d6968674d3a6a4ab05ae85c4d27de1b97a7c (diff)
downloadlcms2-cfce6b9fa02f1a2ba8dfb6d27cd20d9934cd3cdb.tar.gz
Prevent segfault on atoi()
Prevent segfaults on atoi when input buffer is NULL (harmless, non-exploitable)
Diffstat (limited to 'src/cmscgats.c')
-rw-r--r--src/cmscgats.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/cmscgats.c b/src/cmscgats.c
index 784f841..b813e9a 100644
--- a/src/cmscgats.c
+++ b/src/cmscgats.c
@@ -1496,6 +1496,14 @@ cmsBool CMSEXPORT cmsIT8SetDataFormat(cmsHANDLE h, int n, const char *Sample)
return SetDataFormat(it8, n, Sample);
}
+// A safe atoi that returns 0 when NULL input is given
+static
+cmsInt32Number satoi(const char* b)
+{
+ if (b == NULL) return 0;
+ return atoi(b);
+}
+
static
void AllocateDataSet(cmsIT8* it8)
{
@@ -1503,8 +1511,8 @@ void AllocateDataSet(cmsIT8* it8)
if (t -> Data) return; // Already allocated
- t-> nSamples = atoi(cmsIT8GetProperty(it8, "NUMBER_OF_FIELDS"));
- t-> nPatches = atoi(cmsIT8GetProperty(it8, "NUMBER_OF_SETS"));
+ t-> nSamples = satoi(cmsIT8GetProperty(it8, "NUMBER_OF_FIELDS"));
+ t-> nPatches = satoi(cmsIT8GetProperty(it8, "NUMBER_OF_SETS"));
if (t -> nSamples < 0 || t->nSamples > 0x7ffe || t->nPatches < 0 || t->nPatches > 0x7ffe)
{
@@ -1677,11 +1685,11 @@ void WriteHeader(cmsIT8* it8, SAVESTREAM* fp)
break;
case WRITE_HEXADECIMAL:
- Writef(fp, "\t0x%X", atoi(p ->Value));
+ Writef(fp, "\t0x%X", satoi(p ->Value));
break;
case WRITE_BINARY:
- Writef(fp, "\t0x%B", atoi(p ->Value));
+ Writef(fp, "\t0x%B", satoi(p ->Value));
break;
case WRITE_PAIR:
@@ -1710,7 +1718,7 @@ void WriteDataFormat(SAVESTREAM* fp, cmsIT8* it8)
WriteStr(fp, "BEGIN_DATA_FORMAT\n");
WriteStr(fp, " ");
- nSamples = atoi(cmsIT8GetProperty(it8, "NUMBER_OF_FIELDS"));
+ nSamples = satoi(cmsIT8GetProperty(it8, "NUMBER_OF_FIELDS"));
for (i = 0; i < nSamples; i++) {
@@ -1733,7 +1741,7 @@ void WriteData(SAVESTREAM* fp, cmsIT8* it8)
WriteStr (fp, "BEGIN_DATA\n");
- t->nPatches = atoi(cmsIT8GetProperty(it8, "NUMBER_OF_SETS"));
+ t->nPatches = satoi(cmsIT8GetProperty(it8, "NUMBER_OF_SETS"));
for (i = 0; i < t-> nPatches; i++) {