Skip to content

gtp_v2: allow building IE_Indication, IE_MMContext_EPS, and PCO_S_Nssai without explicit length - #5296

Open
pro-laxmi wants to merge 1 commit into
secdev:masterfrom
pro-laxmi:fix/gtpv2-build-conditions
Open

pro-laxmi wants to merge 1 commit into
secdev:masterfrom
pro-laxmi:fix/gtpv2-build-conditions

Conversation

@pro-laxmi

Copy link
Copy Markdown

Description

When building IE_Indication, IE_MMContext_EPS, or PCO_S_Nssai with default parameters or without manually calculating and passing length, ConditionalField conditions evaluate pkt.length > ... when pkt.length is None. In Python 3, this raises TypeError: '>' not supported between instances of 'NoneType' and 'int':

from scapy.all import raw, load_contrib
load_contrib("gtp_v2")
from scapy.contrib.gtp_v2 import IE_Indication, IE_MMContext_EPS, PCO_S_Nssai

raw(IE_Indication())
# TypeError: While building field 'DAF': '>' not supported between instances of 'NoneType' and 'int'

raw(IE_MMContext_EPS())
# TypeError: While building field 'fields': '>' not supported between instances of 'NoneType' and 'int'

raw(PCO_S_Nssai())
# TypeError: While building field 'SST': '>' not supported between instances of 'NoneType' and 'int'

Fix

  1. IE_Indication: Set default length to 3 (matching the 3 mandatory octets of basic flags defined in 3GPP TS 29.274 Table 8.12-1: Octets 5–7). Dissection and explicit lengths (length=8) remain unchanged.
  2. IE_MMContext_EPS: In ConditionalField and StrLenField("fields", ...), guard pkt.length against None (pkt.length > 40 if pkt.length is not None else False) so the 41-octet base EPS context builds cleanly without an explicit length.
  3. PCO_S_Nssai: In ConditionalField, guard against pkt.length is None, defaulting mandatory SST to True, allowing PCO_Protocol.post_build to automatically calculate the length.

Tests

Added test cases in test/contrib/gtp_v2.uts verifying that IE_Indication(PS=1), IE_MMContext_EPS(), and PCO_S_Nssai build and dissect cleanly without requiring an explicit length parameter. Full unit tests pass via test/run_tests -P "load_contrib('gtp_v2')" -t test/contrib/gtp_v2.uts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant