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

Fix for a buffer management bug in parsing frames from a websocket. #26

Merged
merged 1 commit into from Sep 4, 2015

Conversation

krokodilerian
Copy link
Contributor

In buffer management/parsing, turns out that if you had a piece of a SIP
packet in the previous buffer (input), and in the current one the remainder
of that packet and another one, it will just copy until the end of input,
instead of just the needed length.

The calculations were also done at the wrong place, they had to be done after
the allocation of the new buffer.

The bug meant that:

  • Some packets were getting eaten, resulting in random disconnections and
    other dropped events;
  • Sometimes repro would crash;
  • Or, if compiled with ASAN, it would always crash.

Also, it was more pronounced with TLS.

A way to reproduce this on the original repro is to create a stream with the HTTP upgrade request in the beginning and some SIP packets after that (I did it with 20k file), and just sending it with something like
cat req | (sleep 2; telnet repro 5066)
would crash the server.

In buffer management/parsing, turns out that if you had a piece of a SIP
packet in the previous buffer (input), and in the current one the remainder
of that packet and another one, it will just copy until the end of input,
instead of just the needed length.

The calculations were also done at the wrong place, they had to be done after
the allocation of the new buffer.

The bug meant that:
- Some packets were getting eaten, resulting in random disconnections and
other dropped events;
- Sometimes repro would crash;
- Or, if compiled with ASAN, it would always crash.

Also, it was more pronounced with TLS.
@sgodin
Copy link
Member

sgodin commented Sep 4, 2015

Awesome - thanks for the contribution!!

sgodin added a commit that referenced this pull request Sep 4, 2015
Fix for a buffer management bug in parsing frames from a websocket.

In buffer management/parsing, turns out that if you had a piece of a SIP
packet in the previous buffer (input), and in the current one the remainder
of that packet and another one, it will just copy until the end of input,
instead of just the needed length.

The calculations were also done at the wrong place, they had to be done after
the allocation of the new buffer.

The bug meant that:

Some packets were getting eaten, resulting in random disconnections and other dropped events;
Sometimes repro would crash;
Or, if compiled with ASAN, it would always crash.
Also, it was more pronounced with TLS.

A way to reproduce this on the original repro is to create a stream with the HTTP upgrade request in the beginning and some SIP packets after that (I did it with 20k file), and just sending it with something like
cat req | (sleep 2; telnet repro 5066)
would crash the server.
@sgodin sgodin merged commit 51a1a25 into resiprocate:master Sep 4, 2015
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.

None yet

2 participants