From 04bfe7a91223ba15d868f7165e49328b1c6e86c3 Mon Sep 17 00:00:00 2001 From: Flavio Cruz Date: Wed, 10 May 2023 01:39:54 -0400 Subject: Check that msgt_name is always smaller than 255. For the x86_64 ABI we want this to always fit into 1 byte. Even for regular i686, msgt_name is always smaller than 25 (MACH_MSG_TYPE_LAST) and we don't have plans to have more names. Also throw an error if we deemed an RPC to be "TooLong" as that won't work or work badly. Tested by cross-compiling a basic Hurd system. Message-Id: --- type.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/type.c b/type.c index 15843e3..c46f8f8 100644 --- a/type.c +++ b/type.c @@ -323,19 +323,21 @@ itUseLong(const ipc_type_t *it) if ((it->itVarArray && !it->itInLine) || it->itIndefinite) uselong = ShouldBeLong; + /* Check that msgt_name fits into 1 byte as the x86_64 ABI requires it. + Note that MACH_MSG_TYPE_POLYMORPHIC is -1 hence it is ignored. */ if (((it->itInName != MACH_MSG_TYPE_POLYMORPHIC) && (it->itInName >= (1<<8))) || ((it->itOutName != MACH_MSG_TYPE_POLYMORPHIC) && - (it->itOutName >= (1<<8))) || - (it->itSize >= (1<<8)) || + (it->itOutName >= (1<<8)))) { + error("Cannot have msgt_name greater than 255"); + uselong = TooLong; + } + + if ((it->itSize >= (1<<8)) || (it->itNumber >= (1<<12))) uselong = MustBeLong; - if (((it->itInName != MACH_MSG_TYPE_POLYMORPHIC) && - (it->itInName >= (1<<16))) || - ((it->itOutName != MACH_MSG_TYPE_POLYMORPHIC) && - (it->itOutName >= (1<<16))) || - (it->itSize >= (1<<16))) + if (it->itSize >= (1<<16)) uselong = TooLong; return uselong; @@ -416,7 +418,7 @@ itCheckDecl(identifier_t name, ipc_type_t *it) uselong = itUseLong(it); if (uselong == TooLong) - warn("%s: too big for mach_msg_type_long_t", name); + error("%s: too big for mach_msg_type_long_t", name); it->itLongForm = itCheckIsLong(it, it->itFlags, (int)uselong >= (int)ShouldBeLong, name); } -- cgit v1.2.3