summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2022-05-08 12:35:00 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2022-05-08 12:38:08 -0700
commitee33ecf31706877e1ab7dc257fadbb3eb535da50 (patch)
treead6e233c65afa8031f8b57af6e4f568bc52f82fd
parent4a1d0977dbb6eb960ca4deedba90940bcaeecefb (diff)
Convert code to use FSmallocarray() & FSreallocarray()
Provides automatic integer overflow checking in allocation size calculations (Though we already have explicit checks before using values provided over the protocol in calculations, so many were already manually checked.) Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--src/FSFontInfo.c6
-rw-r--r--src/FSFtNames.c2
-rw-r--r--src/FSGetCats.c2
-rw-r--r--src/FSListCats.c2
-rw-r--r--src/FSListExt.c2
-rw-r--r--src/FSOpenServ.c2
-rw-r--r--src/FSQGlyphs.c6
-rw-r--r--src/FSQXExt.c6
-rw-r--r--src/FSQXInfo.c2
9 files changed, 15 insertions, 15 deletions
diff --git a/src/FSFontInfo.c b/src/FSFontInfo.c
index fd807ae..3a5fe43 100644
--- a/src/FSFontInfo.c
+++ b/src/FSFontInfo.c
@@ -130,7 +130,7 @@ FSListFontsWithXInfo(
if (fhdr) {
#define ResizeArray(var, type) { \
- type **tmp = FSrealloc(var, sizeof(type *) * size); \
+ type **tmp = FSreallocarray(var, size, sizeof(type *)); \
if (tmp) \
var = tmp; \
else \
@@ -144,7 +144,7 @@ FSListFontsWithXInfo(
ResizeArray(pd, unsigned char)
} else {
#define InitArray(var, type) \
- if ((var = FSmalloc(sizeof(type *) * size)) == NULL) { \
+ if ((var = FSmallocarray(size, sizeof(type *))) == NULL) { \
goto badmem; \
}
@@ -184,7 +184,7 @@ FSListFontsWithXInfo(
goto cleanpi;
#endif
- po[i] = FSmalloc(pi[i]->num_offsets * sizeof(FSPropOffset));
+ po[i] = FSmallocarray(pi[i]->num_offsets, sizeof(FSPropOffset));
if (!po[i])
goto cleanpi;
pd[i] = FSmalloc(pi[i]->data_len);
diff --git a/src/FSFtNames.c b/src/FSFtNames.c
index 1dea246..23c93a3 100644
--- a/src/FSFtNames.c
+++ b/src/FSFtNames.c
@@ -98,7 +98,7 @@ FSListFonts(
&& rep.length <= (SIZE_MAX >> 2)
#endif
) {
- flist = FSmalloc(rep.nFonts * sizeof(char *));
+ flist = FSmallocarray(rep.nFonts, sizeof(char *));
rlen = (rep.length << 2) - SIZEOF(fsListFontsReply);
c = FSmalloc(rlen + 1);
diff --git a/src/FSGetCats.c b/src/FSGetCats.c
index d8fae40..4c27a34 100644
--- a/src/FSGetCats.c
+++ b/src/FSGetCats.c
@@ -79,7 +79,7 @@ FSGetCatalogues(
&& rep.length <= (SIZE_MAX >> 2)
#endif
) {
- list = FSmalloc(rep.num_catalogues * sizeof(char *));
+ list = FSmallocarray(rep.num_catalogues, sizeof(char *));
rlen = (rep.length << 2) - SIZEOF(fsGetCataloguesReply);
c = FSmalloc(rlen + 1);
if ((!list) || (!c)) {
diff --git a/src/FSListCats.c b/src/FSListCats.c
index 2bc1393..9fb380c 100644
--- a/src/FSListCats.c
+++ b/src/FSListCats.c
@@ -97,7 +97,7 @@ FSListCatalogues(
&& rep.length <= (SIZE_MAX>>2)
#endif
) {
- clist = FSmalloc(rep.num_catalogues * sizeof(char *));
+ clist = FSmallocarray(rep.num_catalogues, sizeof(char *));
rlen = (rep.length << 2) - SIZEOF(fsListCataloguesReply);
c = FSmalloc(rlen + 1);
diff --git a/src/FSListExt.c b/src/FSListExt.c
index 8d83bd3..a4249f4 100644
--- a/src/FSListExt.c
+++ b/src/FSListExt.c
@@ -79,7 +79,7 @@ FSListExtensions(
&& rep.length <= (SIZE_MAX>>2)
#endif
) {
- list = FSmalloc(rep.nExtensions * sizeof(char *));
+ list = FSmallocarray(rep.nExtensions, sizeof(char *));
rlen = (rep.length << 2) - SIZEOF(fsListExtensionsReply);
c = FSmalloc(rlen + 1);
if ((!list) || (!c)) {
diff --git a/src/FSOpenServ.c b/src/FSOpenServ.c
index faebe13..5acef9f 100644
--- a/src/FSOpenServ.c
+++ b/src/FSOpenServ.c
@@ -167,7 +167,7 @@ FSOpenServer(const char *server)
}
#endif
- alts = FSmalloc(sizeof(AlternateServer) * prefix.num_alternates);
+ alts = FSmallocarray(prefix.num_alternates, sizeof(AlternateServer));
if (!alts) {
goto fail;
}
diff --git a/src/FSQGlyphs.c b/src/FSQGlyphs.c
index e40c88a..662da36 100644
--- a/src/FSQGlyphs.c
+++ b/src/FSQGlyphs.c
@@ -93,7 +93,7 @@ FSQueryXBitmaps8(
return FSBadAlloc;
#endif
- offs = FSmalloc(sizeof(FSOffset) * reply.num_chars);
+ offs = FSmallocarray(reply.num_chars, sizeof(FSOffset));
*offsets = offs;
if (!offs)
return FSBadAlloc;
@@ -160,7 +160,7 @@ FSQueryXBitmaps16(
if (str_len > SIZE_MAX/SIZEOF(fsChar2b_version1))
return FSBadAlloc;
- swapped_str = FSmalloc(SIZEOF(fsChar2b_version1) * str_len);
+ swapped_str = FSmallocarray(str_len, SIZEOF(fsChar2b_version1));
if (!swapped_str)
return FSBadAlloc;
for (unsigned long i = 0; i < str_len; i++) {
@@ -182,7 +182,7 @@ FSQueryXBitmaps16(
if(reply.num_chars > SIZE_MAX/sizeof(FSOffset))
return FSBadAlloc;
#endif
- offs = FSmalloc(sizeof(FSOffset) * reply.num_chars);
+ offs = FSmallocarray(reply.num_chars, sizeof(FSOffset));
*offsets = offs;
if (!offs)
return FSBadAlloc;
diff --git a/src/FSQXExt.c b/src/FSQXExt.c
index 1469636..65f35b1 100644
--- a/src/FSQXExt.c
+++ b/src/FSQXExt.c
@@ -100,7 +100,7 @@ FSQueryXExtents8(
return FSBadAlloc;
#endif
- ext = FSmalloc(sizeof(FSXCharInfo) * reply.num_extents);
+ ext = FSmallocarray(reply.num_extents, sizeof(FSXCharInfo));
*extents = ext;
if (!ext)
return FSBadAlloc;
@@ -141,7 +141,7 @@ FSQueryXExtents16(
{
fsChar2b_version1 *swapped_str;
- swapped_str = FSmalloc(SIZEOF(fsChar2b_version1) * str_len);
+ swapped_str = FSmallocarray(str_len, SIZEOF(fsChar2b_version1));
if (!swapped_str)
return FSBadAlloc;
for (unsigned long i = 0; i < str_len; i++) {
@@ -164,7 +164,7 @@ FSQueryXExtents16(
return FSBadAlloc;
#endif
- ext = FSmalloc(sizeof(FSXCharInfo) * reply.num_extents);
+ ext = FSmallocarray(reply.num_extents, sizeof(FSXCharInfo));
*extents = ext;
if (!ext)
return FSBadAlloc;
diff --git a/src/FSQXInfo.c b/src/FSQXInfo.c
index de776ce..f497a09 100644
--- a/src/FSQXInfo.c
+++ b/src/FSQXInfo.c
@@ -97,7 +97,7 @@ FSQueryXInfo(
#endif
/* prepare for prop data */
- offset_data = FSmalloc(props->num_offsets * sizeof(FSPropOffset));
+ offset_data = FSmallocarray(props->num_offsets, sizeof(FSPropOffset));
if (!offset_data)
return FSBadAlloc;
pdata = FSmalloc(props->data_len);