From: Andrei Pavel Date: Thu, 20 Jun 2024 10:27:54 +0000 (+0300) Subject: [#3323] typed enums to appease ubsan X-Git-Tag: Kea-2.7.0~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c61324b545e69c6fd61f738aba121128c736bebf;p=thirdparty%2Fkea.git [#3323] typed enums to appease ubsan example of UBSan error: runtime error: load of value 65536, which is not a valid value for type 'const HeaderFlag' --- diff --git a/src/lib/cc/data.h b/src/lib/cc/data.h index c6925138f3..a4be0ed674 100644 --- a/src/lib/cc/data.h +++ b/src/lib/cc/data.h @@ -136,7 +136,7 @@ public: /// /// any is a special type used in list specifications, specifying that the /// elements can be of any type. - enum types { + enum types : int { integer = 0, real = 1, boolean = 2, diff --git a/src/lib/dns/message.h b/src/lib/dns/message.h index d5c57950d0..1dea110ddb 100644 --- a/src/lib/dns/message.h +++ b/src/lib/dns/message.h @@ -199,7 +199,7 @@ public: /// introducing a separately defined class considering the balance /// between the complexity and advantage, but hopefully the cast notation /// is sufficiently ugly to prevent proliferation of the usage. - enum HeaderFlag { + enum HeaderFlag : int { HEADERFLAG_QR = 0x8000, // Query (if cleared) or response (if set) HEADERFLAG_AA = 0x0400, // Authoritative answer HEADERFLAG_TC = 0x0200, // Truncation @@ -239,7 +239,7 @@ public: /// /// Future Extension: We'll probably also define constants for /// the section names used in dynamic updates in future versions. - enum Section { + enum Section : int { SECTION_QUESTION = 0, // Question section SECTION_ANSWER = 1, // Answer section SECTION_AUTHORITY = 2, // Authority section diff --git a/src/lib/eval/token.h b/src/lib/eval/token.h index b37a9867d5..9f0c10d99b 100644 --- a/src/lib/eval/token.h +++ b/src/lib/eval/token.h @@ -542,7 +542,7 @@ class TokenPkt : public Token { public: /// @brief enum value that determines the field. - enum MetadataType { + enum MetadataType : int { IFACE, ///< interface name (string) SRC, ///< source (IP address) DST, ///< destination (IP address) @@ -591,7 +591,7 @@ class TokenPkt4 : public Token { public: /// @brief enum value that determines the field. - enum FieldType { + enum FieldType : int { CHADDR, ///< chaddr field (up to 16 bytes link-layer address) GIADDR, ///< giaddr (IPv4 address) CIADDR, ///< ciaddr (IPv4 address) @@ -644,7 +644,7 @@ private: class TokenPkt6 : public Token { public: /// @brief enum value that determines the field. - enum FieldType { + enum FieldType : int { MSGTYPE, ///< msg type TRANSID ///< transaction id (integer but manipulated as a string) }; @@ -696,7 +696,7 @@ class TokenRelay6Field : public Token { public: /// @brief enum value that determines the field. - enum FieldType { + enum FieldType : int { PEERADDR, ///< Peer address field (IPv6 address) LINKADDR ///< Link address field (IPv6 address) }; @@ -1091,7 +1091,7 @@ class TokenVendor : public TokenOption { public: /// @brief Specifies a field of the vendor option - enum FieldType { + enum FieldType : int { SUBOPTION, ///< If this token fetches a suboption, not a field. ENTERPRISE_ID, ///< enterprise-id field (vendor-info, vendor-class) EXISTS, ///< vendor[123].exists