Skip to content

AppType.get(name) never matches an existing member and silently mints a port=-1 member instead #734

Description

@JarryShaw

Describe the bug

AppType.get has three defects on the same code path. The second silently returns wrong data.

>>> AppType.get('http')
TypeError: 'http' already in use as <AppType.http: 80 [tcp|udp|sctp]>
>>> AppType.get('ssh')
<AppType.ssh: -1 [undefined]>        # real ssh port is 22; enum grew 8182 -> 8183
>>> AppType.get(999999, proto='tcp')
unknown [999999 - tcp]              # ports are 16-bit

Root cause, pcapkit/const/reg/apptype.py:30620 — the string path tests key in AppType.__members_proto__, but that dict is keyed by TransportProtocol, so a str key never matches. It almost certainly meant AppType.__members__. Every name lookup therefore falls through to the mint branch:

  • name already a member → extend_enum raises TypeError: already in use
  • name not a member → mints a new member with port=-1, returns it, and permanently grows the enum

Separately, the same except ValueError wrapper swallows the guard that should reject out-of-range ports, so get(999999) mints instead of raising.

Expected behavior

get('http') returns the existing member. get('ssh') returns port 22. get(999999) raises, as every other registry does for an out-of-range code (see tests/const/test_const_enum_builtin_parity.py, issue #647).

Additional context

AppType is generated. The fix belongs in the template at pcapkit/vendor/reg/apptype.py and the generated pcapkit/const/reg/apptype.py, kept in lockstep — test_const_enum_builtin_parity.py lists pcapkit.vendor.reg.apptype in BESPOKE_TEMPLATES and renders the template to compare it character-for-character against the generated module. The crawler hits live IANA endpoints, so it cannot be re-run in CI.

Independent of #732, which would restructure these files: the #732 plan puts this fix first precisely because it carries no design dependency. Worth fixing once here rather than replicating into N classes later.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    blockedDeferred pending another issue or decision; see the last comment for what unblocks itbugfixPull requests that fix a defect (fix: subject prefix)

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions