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 getCommandOption for command-only packets #1718

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

s-genereux
Copy link

@s-genereux s-genereux commented Feb 18, 2025

Pcap++ crashes when you attempt to getCommandOption() of a command-only FTP request packet. I traced the issue to SingleCommandTextProtocol::getCommandOptionInternal().

To check for command-only packets, it compares the offset to the option field returned by getArgumentFieldOffset() to the raw data length minus 1. This should be minus 2;

  1. -1 to account for the fact getArgumentFieldOffset() returns the position of the CR in the CRLF terminator in the case of command-only packets.
  2. -1 to account for the fact we are comparing a length value to a zero-indexed position value.

This PR makes the necessary change in SingleCommandTextProtocol.cpp and adds a command-only FTP request packet testcase to Packet++Test

@s-genereux s-genereux requested a review from seladb as a code owner February 18, 2025 17:11
Copy link
Collaborator

@egecetin egecetin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fails due to brownouts. Need to run CI later

Copy link

codecov bot commented Feb 19, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.12%. Comparing base (3292f14) to head (b88e964).

Additional details and impacted files
@@           Coverage Diff            @@
##              dev    #1718    +/-   ##
========================================
  Coverage   83.11%   83.12%            
========================================
  Files         279      279            
  Lines       48399    48408     +9     
  Branches    10237    10617   +380     
========================================
+ Hits        40227    40238    +11     
- Misses       7035     7439   +404     
+ Partials     1137      731   -406     
Flag Coverage Δ
alpine320 75.09% <100.00%> (+0.01%) ⬆️
fedora40 75.15% <100.00%> (+0.04%) ⬆️
macos-13 80.61% <100.00%> (+0.01%) ⬆️
macos-14 80.61% <100.00%> (+0.01%) ⬆️
macos-15 80.58% <100.00%> (+0.01%) ⬆️
mingw32 70.85% <100.00%> (+0.01%) ⬆️
mingw64 70.80% <100.00%> (-0.01%) ⬇️
npcap 85.23% <100.00%> (ø)
rhel94 74.97% <100.00%> (+0.02%) ⬆️
ubuntu2004 58.59% <30.00%> (+<0.01%) ⬆️
ubuntu2004-zstd 58.71% <30.00%> (+<0.01%) ⬆️
ubuntu2204 74.91% <100.00%> (+0.03%) ⬆️
ubuntu2204-icpx 61.29% <100.00%> (+0.01%) ⬆️
ubuntu2404 75.13% <100.00%> (+0.02%) ⬆️
unittest 83.12% <100.00%> (+<0.01%) ⬆️
windows-2019 85.26% <100.00%> (+<0.01%) ⬆️
windows-2022 85.28% <100.00%> (+<0.01%) ⬆️
winpcap 85.25% <100.00%> (+0.01%) ⬆️
xdp 50.42% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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.

2 participants