From dc14193743457abb1bea25789c9299da54743b11 Mon Sep 17 00:00:00 2001 From: elajkat <lajos.katona@est.tech> Date: Thu, 6 Jun 2024 12:34:03 +0200 Subject: [PATCH] Raise ValueError in case unpack_from returns zero length Merge-conflicts: os_ken/ofproto/ofproto_v1_3_parser.py os_ken/ofproto/ofproto_v1_4_parser.py os_ken/ofproto/ofproto_v1_5_parser.py Closes-Bug: #2067973 Closes-Bug: #2067970 Change-Id: If3327be6c0a4c25173473fb8879d111544d77af5 (cherry picked from commit 2f30f44406535991ec982608d04c8893b8fda9ad) --- os_ken/ofproto/ofproto_v1_3_parser.py | 2 ++ os_ken/ofproto/ofproto_v1_4_parser.py | 2 ++ os_ken/ofproto/ofproto_v1_5_parser.py | 2 ++ 3 files changed, 6 insertions(+) diff --git a/os_ken/ofproto/ofproto_v1_3_parser.py b/os_ken/ofproto/ofproto_v1_3_parser.py index 6e42847a..1d02a5a5 100644 --- a/os_ken/ofproto/ofproto_v1_3_parser.py +++ b/os_ken/ofproto/ofproto_v1_3_parser.py @@ -1617,6 +1617,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_] diff --git a/os_ken/ofproto/ofproto_v1_4_parser.py b/os_ken/ofproto/ofproto_v1_4_parser.py index 10c5a70c..5f4c37a2 100644 --- a/os_ken/ofproto/ofproto_v1_4_parser.py +++ b/os_ken/ofproto/ofproto_v1_4_parser.py @@ -884,6 +884,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_] diff --git a/os_ken/ofproto/ofproto_v1_5_parser.py b/os_ken/ofproto/ofproto_v1_5_parser.py index ce462e58..94249a40 100644 --- a/os_ken/ofproto/ofproto_v1_5_parser.py +++ b/os_ken/ofproto/ofproto_v1_5_parser.py @@ -1027,6 +1027,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_]