From 2f30f44406535991ec982608d04c8893b8fda9ad Mon Sep 17 00:00:00 2001 From: elajkat Date: Thu, 6 Jun 2024 12:34:03 +0200 Subject: [PATCH] Raise ValueError in case unpack_from returns zero length Closes-Bug: #2067973 Closes-Bug: #2067970 Change-Id: If3327be6c0a4c25173473fb8879d111544d77af5 --- os_ken/ofproto/ofproto_v1_3_parser.py | 4 ++++ os_ken/ofproto/ofproto_v1_4_parser.py | 4 ++++ os_ken/ofproto/ofproto_v1_5_parser.py | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/os_ken/ofproto/ofproto_v1_3_parser.py b/os_ken/ofproto/ofproto_v1_3_parser.py index ca2d94ca..58147479 100644 --- a/os_ken/ofproto/ofproto_v1_3_parser.py +++ b/os_ken/ofproto/ofproto_v1_3_parser.py @@ -1616,6 +1616,8 @@ class OFPPropBase(StringifyMixin): @classmethod def parse(cls, buf): (type_, length) = struct.unpack_from(cls._PACK_STR, buf, 0) + if not length: + raise ValueError rest = buf[utils.round_up(length, 8):] try: subcls = cls._TYPES[type_] @@ -6602,6 +6604,8 @@ class NXTPacketIn2Prop(OFPPropBase): @classmethod def parse(cls, buf): (type_, length) = struct.unpack_from(cls._PACK_STR, buf, 0) + if not length: + raise ValueError rest = buf[utils.round_up(length, 8):] try: subcls = cls._TYPES[type_] diff --git a/os_ken/ofproto/ofproto_v1_4_parser.py b/os_ken/ofproto/ofproto_v1_4_parser.py index 6bbc39ee..bdbb70b0 100644 --- a/os_ken/ofproto/ofproto_v1_4_parser.py +++ b/os_ken/ofproto/ofproto_v1_4_parser.py @@ -900,6 +900,8 @@ class OFPPropBase(StringifyMixin): @classmethod def parse(cls, buf): (type_, length) = struct.unpack_from(cls._PACK_STR, buf, 0) + if not length: + raise ValueError rest = buf[utils.round_up(length, 8):] try: subcls = cls._TYPES[type_] @@ -5948,6 +5950,8 @@ class NXTPacketIn2Prop(OFPPropBase): @classmethod def parse(cls, buf): (type_, length) = struct.unpack_from(cls._PACK_STR, buf, 0) + if not length: + raise ValueError rest = buf[utils.round_up(length, 8):] try: subcls = cls._TYPES[type_] diff --git a/os_ken/ofproto/ofproto_v1_5_parser.py b/os_ken/ofproto/ofproto_v1_5_parser.py index 61c13ef0..59297f21 100644 --- a/os_ken/ofproto/ofproto_v1_5_parser.py +++ b/os_ken/ofproto/ofproto_v1_5_parser.py @@ -1043,6 +1043,8 @@ class OFPPropBase(StringifyMixin): @classmethod def parse(cls, buf): (type_, length) = struct.unpack_from(cls._PACK_STR, buf, 0) + if not length: + raise ValueError rest = buf[utils.round_up(length, 8):] try: subcls = cls._TYPES[type_] @@ -7049,6 +7051,8 @@ class NXTPacketIn2Prop(OFPPropBase): @classmethod def parse(cls, buf): (type_, length) = struct.unpack_from(cls._PACK_STR, buf, 0) + if not length: + raise ValueError rest = buf[utils.round_up(length, 8):] try: subcls = cls._TYPES[type_]