Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diameter.__bytes__ has side effects (messes up len and cmd) #647

Open
pfirsich opened this issue Nov 24, 2022 · 1 comment
Open

Diameter.__bytes__ has side effects (messes up len and cmd) #647

pfirsich opened this issue Nov 24, 2022 · 1 comment
Labels

Comments

@pfirsich
Copy link

Describe the bug
After parsing a Diameter message, calling __bytes__ (e.g. by printing it)

To Reproduce
Steps to reproduce the behavior:

diam = dpkt.diameter.Diameter(data)
print(diam.len) # prints a number
print(diam)
print(diam.len) # prints a bytes object

Expected behavior
No fields should be affected by printing the object. len and cmd should stay the same.

Details(please complete the following information):

  • OS: Red Hat Enterprise Linux Server 7.9 (Maipo)
  • Python Version: 3.6.6

Sadly I cannot upload any pcap files (legal reasons), but the issue is very obvious.

Additional context
The cause of the problem is that __bytes__ calls pack_hdr which changes the member variables. Ideally it would not touch them or at the very least restore them: https://github.com/kbandla/dpkt/blob/master/dpkt/diameter.py#L106

@pfirsich pfirsich changed the title Diameter.__bytes__ has side effects (messes up len and cmd Diameter.__bytes__ has side effects (messes up len and cmd) Nov 24, 2022
@obormot obormot added the bug label Nov 28, 2022
@obormot
Copy link
Collaborator

obormot commented Nov 28, 2022

Good catch. Assigning len and cmd in both the unpacking and packing functions definitely seems wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants