summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlavio Cruz <flaviocruz@gmail.com>2023-05-10 01:39:54 -0400
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2023-05-11 01:27:19 +0200
commit04bfe7a91223ba15d868f7165e49328b1c6e86c3 (patch)
treea92285f9e723b1a8738d81274c22550c6be25beb
parent4c0f2ff0a1432f7e1794cf29b1a4667e3a0f8f89 (diff)
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: <ZFsuKtiLdwNpD6b1@jupiter.tail36e24.ts.net>
-rw-r--r--type.c18
1 files 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);
}