summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Astals Cid <aacid@kde.org>2008-09-28 19:25:53 +0200
committerAlbert Astals Cid <aacid@kde.org>2008-09-28 19:25:53 +0200
commit3cb5b7fc5ae168ef58fd1905f61c1b9abe6cb86c (patch)
tree68914ae47841f5a9bd27c3ced05412e1c1dacba5
parentaa7ef03af49f74ed558dcbab8ad4c594bb2b7d53 (diff)
Introduce greallocn_checkoverflow and use it in FoFiTrueType::parse
Fixes the other part of bug 17811
-rw-r--r--fofi/FoFiTrueType.cc4
-rw-r--r--goo/gmem.cc21
-rw-r--r--goo/gmem.h1
3 files changed, 24 insertions, 2 deletions
diff --git a/fofi/FoFiTrueType.cc b/fofi/FoFiTrueType.cc
index 8502f241..60906aef 100644
--- a/fofi/FoFiTrueType.cc
+++ b/fofi/FoFiTrueType.cc
@@ -1908,8 +1908,8 @@ void FoFiTrueType::parse() {
pos += 16;
}
nTables -= wrongTables;
- tables = (TrueTypeTable *)greallocn(tables, nTables, sizeof(TrueTypeTable));
- if (!parsedOk) {
+ tables = (TrueTypeTable *)greallocn_checkoverflow(tables, nTables, sizeof(TrueTypeTable));
+ if (!parsedOk || tables == NULL) {
return;
}
diff --git a/goo/gmem.cc b/goo/gmem.cc
index a64ddb4a..2a638dea 100644
--- a/goo/gmem.cc
+++ b/goo/gmem.cc
@@ -227,6 +227,27 @@ void *greallocn(void *p, int nObjs, int objSize) GMEM_EXCEP {
return grealloc(p, n);
}
+void *greallocn_checkoverflow(void *p, int nObjs, int objSize) GMEM_EXCEP {
+ int n;
+
+ if (nObjs == 0) {
+ if (p) {
+ gfree(p);
+ }
+ return NULL;
+ }
+ n = nObjs * objSize;
+ if (objSize <= 0 || nObjs < 0 || nObjs >= INT_MAX / objSize) {
+#if USE_EXCEPTIONS
+ throw GMemException();
+#else
+ fprintf(stderr, "Bogus memory allocation size\n");
+ return NULL;
+#endif
+ }
+ return grealloc(p, n);
+}
+
void gfree(void *p) {
#ifdef DEBUG_MEM
int size;
diff --git a/goo/gmem.h b/goo/gmem.h
index 760cadc7..ff9b24dd 100644
--- a/goo/gmem.h
+++ b/goo/gmem.h
@@ -71,6 +71,7 @@ extern void *grealloc(void *p, size_t size) GMEM_EXCEP;
extern void *gmallocn(int nObjs, int objSize) GMEM_EXCEP;
extern void *gmallocn_checkoverflow(int nObjs, int objSize) GMEM_EXCEP;
extern void *greallocn(void *p, int nObjs, int objSize) GMEM_EXCEP;
+extern void *greallocn_checkoverflow(void *p, int nObjs, int objSize) GMEM_EXCEP;
/*
* Same as free, but checks for and ignores NULL pointers.