Skip to content

service_scan: increase probe file line buffer and add truncation error - #3367

Closed
Ashutosh-177 wants to merge 2 commits into
nmap:masterfrom
Ashutosh-177:fix/probe-line-buffer-too-small
Closed

service_scan: increase probe file line buffer and add truncation error#3367
Ashutosh-177 wants to merge 2 commits into
nmap:masterfrom
Ashutosh-177:fix/probe-line-buffer-too-small

Conversation

@Ashutosh-177

Copy link
Copy Markdown

The line buffer in parse_nmap_service_probe_file() is 2048 bytes. fgets() silently truncates anything longer without any indication that data was lost. When this happens with a Probe line, the rest of the token is read as the next line and triggers a fatal "unexpected Probe token" error -- not very helpful for figuring out what went wrong.

This came up with the QUIC UDP probe, which is longer than 2047 bytes. Instead of a clear "this line is too long" message you just get a confusing parse failure.

The fix bumps the buffer to 16 KB (plenty of headroom for any realistic probe definition) and adds a check right after fgets() that detects when the buffer was filled without reaching a newline. If that happens while not at EOF, it's a definitive truncation and we emit a fatal error with the line number and the actual limit, making future overflows obvious instead of silent.

Fixes #3201

The 2048-byte line buffer in parse_nmap_service_probe_file() silently
truncates any probe definition longer than 2047 characters. A QUIC UDP
probe legitimately exceeds this limit and produces a misleading
"unexpected Probe token" fatal error instead of a clear "line too long"
message.

Increase the buffer to 16 KB, which comfortably fits all current and
anticipated probe entries. Add a truncation guard immediately after
fgets() that fires a descriptive fatal() if a line fills the buffer
without a trailing newline, making future overflow obvious rather than
silent.

Fixes nmap#3201

Signed-off-by: Ashutosh Kumar Singh <ahutoshhjp1067@gmail.com>
Copilot AI review requested due to automatic review settings May 19, 2026 16:54

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Updates parse_nmap_service_probe_file to support longer lines and to explicitly fail fast when encountering probe file lines that exceed the configured buffer size.

Changes:

  • Increased the probe-file line buffer from 2,048 to 16,384 bytes.
  • Added detection of truncated fgets reads and a fatal() error when a line exceeds the buffer.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread service_scan.cc Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@Ashutosh-177

Copy link
Copy Markdown
Author

@copilot apply changes based on the comments in this thread

@nmap-bot nmap-bot closed this in 9893d6e Jul 22, 2026
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.

Service/version detection: Added nmap probes can't be over 2k, and gives incorrect parsing error if they are

2 participants