Fix double incrementing of the packet number#117
Conversation
This commit fixes an issue where the packet number field of the packet header was incorrectly incremented twice. This resulted in the packet number fo a single LOGIN7 packet being 2, rather 1. This violated the TDS protocol definition. Furthermore, firewall rules that restrict traffic based on the TDS protocol filtered out such violating TDS packets. Also, it resulted in tools such as Wireshark not being able to properly parse out the TDS header.
|
@mjaric: Could you please review this PR? It would be great to get this change incorporated into the mainline so that we can move off of our fork of tds. |
|
Thanks! |
|
Just one question, if first packet is zero, would firewall complain too? I'm not sure who could send more than 254 packet as single message, but after 255 counter must be reset. I know that server will return response, but what will happen with firewall I'm not sure |
|
According to the latest TDS spec (v30), starting with an index of 1 is acceptable and what .NET uses. I suspect that it might vary between firewalls whether they properly support a PacketID of 0. However, starting with an ID of 1 is probably the safest bet.
Footnote:
|
This MR fixes an issue where the packet number field of the packet header was incorrectly incremented twice. This resulted in the packet number fo a single LOGIN7 packet being 2, rather 1.
This violated the TDS protocol definition. Furthermore, firewall rules that restrict traffic based on the TDS protocol filtered out such violating TDS packets. Also, it resulted in tools such as Wireshark not being able to properly parse out the TDS header.
Example
Here's an example of two LOGIN7 packets. The packet on the left was generated with SHA 748b2f4. The packet on the right was generated using SHA fe62754. As you can see, the packet number is wrong in the left screenshot.
Issue Origination
I believe the issue was introduced in SHA 748b2f4.
Unit Tests
I've added unit test for boundary testing the
encode_packets/3function.