]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3323] typed enums to appease ubsan
authorAndrei Pavel <andrei@isc.org>
Thu, 20 Jun 2024 10:27:54 +0000 (13:27 +0300)
committerAndrei Pavel <andrei@isc.org>
Thu, 20 Jun 2024 16:32:20 +0000 (19:32 +0300)
example of UBSan error: runtime error: load of value 65536, which is not a valid value for type 'const HeaderFlag'

src/lib/cc/data.h
src/lib/dns/message.h
src/lib/eval/token.h

index c6925138f3de55d74ae695133654ac64964847ab..a4be0ed674a254dce0ffc4aed955fbe620a9d961 100644 (file)
@@ -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,
index d5c57950d0d3cc6ad3b0fcc4b89d271ffb6aa9e5..1dea110ddb0d654eea8b4862819dddc8ae9215ce 100644 (file)
@@ -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:
     ///
     /// <b>Future Extension:</b> 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
index b37a9867d57457fc4bcb3577df4c035e6c97f3d9..9f0c10d99bf805aee5341469ba330a1d60cb6993 100644 (file)
@@ -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