Repository navigation
fix(foundation): reject a registrar code from the wrong enum (#2224) - #2245
Merged
Merged
Conversation
Problem: _check_code only required some enum member. The registry enums compare equal to their values, so a member of another enum was stored and could replace a shipped entry, e.g. register_linktype(TransType.ICMP, ...) overwrote Frame.__proto__[LinkType.ETHERNET]. Fix: _check_code takes the enum the registrar is typed on and checks the type, not equality. register_tcp, register_udp, register_sctp and register_apptype call it too, with number=True, so a plain int is still accepted but an IntEnum member of another enum is not. Test: test_registrar_code_check_unit gains a wrong-enum case for every registrar, each equal by value to one of its own members where possible, asserting RegistryError with every registry snapshotted and unchanged.
Owner
Author
|
Review: GOOD TO GO at
|
Contributor
|
Coverage: 91.56% (unit tier, Python 3.15,
Per-file detail: the |
Owner
Author
|
Ready to merge at
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
make testpasses, and a test case covers the changeWhat is the purpose of your pull request?
fix— bug fixDescription
Closes #2224.
_check_codeaccepted a member of any enum, soregister_linktype(TransType.ICMP, X)replaced the shippedLinkType.ETHERNETentry, since ICMP is 1._check_code(code, kind, *, number=False)passes onlyisinstance(code, kind). Withnumber=Trueit also passes a plainint. Each registrar passes the enum it is annotated with, and those const imports move fromTYPE_CHECKINGto runtime.register_tcp,register_udpandregister_apptype(AppType) andregister_sctp(PayloadProtocolIdentifier) keep plainint. Per the owner's ruling on fix(foundation): registrars accept a member of the wrong enum as the code #2224, they now refuse anything else, such asNoneor'80'. TheirRaises:sections say so.tests/foundation/registry/test_registrar_code_check_unit.pyhas one wrong-enum case per registrar. Where the value types allow, the wrong member is equal by value to one of the registrar's own members. Registries are snapshotted and restored.origin/main, 24 failed.tests/foundationgives 522 passed. The dispatch registry, docstring contract and tier guard give 147 passed.