summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2022-09-07 14:22:44 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2022-09-07 15:32:47 -0700
commit0269c687e954db7aca2a4344e32cb203315a00b6 (patch)
treed7f83585ad157ed0c2fc9a7c40779cfabf9c0a4b
parentb399fc2b3c5c2cf5f0d36d98c372f353a8186d15 (diff)
ICEmsg.h: Add static asserts that message header length <= ICE_OUTBUFSIZE
A message header length larger than ICE_OUTBUFSIZE will cause buffer overflows. Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--include/X11/ICE/ICEmsg.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/include/X11/ICE/ICEmsg.h b/include/X11/ICE/ICEmsg.h
index 9688e3c..426b64c 100644
--- a/include/X11/ICE/ICEmsg.h
+++ b/include/X11/ICE/ICEmsg.h
@@ -33,6 +33,11 @@ Author: Ralph Mor, X Consortium
#include <X11/ICE/ICEconn.h>
+#include <assert.h>
+#ifndef static_assert
+#define static_assert(cond, msg) /* skip for non-C11 compilers */
+#endif
+
_XFUNCPROTOBEGIN
/*
@@ -123,6 +128,8 @@ extern IcePaAuthStatus _IcePaMagicCookie1Proc (
*/
#define IceGetHeader(_iceConn, _major, _minor, _headerSize, _msgType, _pMsg) \
+ static_assert(_headerSize <= 1024, \
+ "Header size larger than ICE_OUTBUFSIZE"); \
if ((_iceConn->outbufptr + _headerSize) > _iceConn->outbufmax) \
IceFlush (_iceConn); \
_pMsg = (_msgType *) _iceConn->outbufptr; \
@@ -133,6 +140,8 @@ extern IcePaAuthStatus _IcePaMagicCookie1Proc (
_iceConn->send_sequence++
#define IceGetHeaderExtra(_iceConn, _major, _minor, _headerSize, _extra, _msgType, _pMsg, _pData) \
+ static_assert(_headerSize <= 1024, \
+ "Header size larger than ICE_OUTBUFSIZE"); \
if ((_iceConn->outbufptr + \
_headerSize + ((_extra) << 3)) > _iceConn->outbufmax) \
IceFlush (_iceConn); \