summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2023-03-03 14:55:19 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2023-03-07 00:06:24 +0000
commit4ece1c842a08c11c1f84b95355801d41cd8435b1 (patch)
treed6f8fb17a745b9635a837c78046ac325b0505413 /include
parent392eb1cd5f2bdb186f0ff7f51abc4dd05ec13709 (diff)
downloadxorg-lib-libXt-4ece1c842a08c11c1f84b95355801d41cd8435b1.tar.gz
Add XtReallocArray() for overflow checking of multiplied args
Uses reallocarray() if available, otherwise checks for overflow itself, if overflow is possible (i.e. in ILP32 & ILP64 environments, but not LP64 with 32-bit ints). Includes unit tests and XtMallocArray() helper macro. Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'include')
-rw-r--r--include/X11/Intrinsic.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/include/X11/Intrinsic.h b/include/X11/Intrinsic.h
index 668b7d5..71199e7 100644
--- a/include/X11/Intrinsic.h
+++ b/include/X11/Intrinsic.h
@@ -1864,6 +1864,12 @@ extern char *XtRealloc(
Cardinal /* num */
);
+extern void *XtReallocArray(
+ void * /* ptr */,
+ Cardinal /* num */,
+ Cardinal /* size */
+);
+
extern void XtFree(
char* /* ptr */
);
@@ -1892,6 +1898,14 @@ extern char *_XtRealloc( /* implementation-private */
int /* line */
);
+extern char *_XtReallocArray( /* implementation-private */
+ char * /* ptr */,
+ Cardinal /* num */,
+ Cardinal /* size */,
+ const char */* file */,
+ int /* line */
+);
+
extern char *_XtCalloc( /* implementation-private */
Cardinal /* num */,
Cardinal /* size */,
@@ -1911,9 +1925,15 @@ extern void _XtPrintMemory( /* implementation-private */
#define XtMalloc(size) _XtMalloc(size, __FILE__, __LINE__)
#define XtRealloc(ptr,size) _XtRealloc(ptr, size, __FILE__, __LINE__)
+#define XtMallocArray(num,size) _XtReallocArray(NULL, num, size, __FILE__, __LINE__)
+#define XtReallocArray(ptr,num,size) _XtReallocArray(ptr, num, size, __FILE__, __LINE__)
#define XtCalloc(num,size) _XtCalloc(num, size, __FILE__, __LINE__)
#define XtFree(ptr) _XtFree(ptr)
+#else
+
+#define XtMallocArray(num,size) XtReallocArray(NULL, num, size)
+
#endif /* ifdef XTTRACEMEMORY */
#define XtNew(type) ((type *) XtMalloc((unsigned) sizeof(type)))