Skip to content

ncat server leaves the socket open in child processes #2843

@m42a

Description

@m42a

Describe the bug
In server mode, when running a command with -e or -c, ncat does not close the socket before executing the child process. Since the parent process exits when the client stops sending data, this can incorrectly cause the client to think more data is incoming.

To Reproduce

ncat -l 1234 -c 'sleep 1; echo response'
echo request | ncat 127.0.0.1 1234

When both commands are run in parallel, the server ncat will exit as soon as the client connects, but the client will wait for a second before the socket is closed (with no response data) by sh exiting.

Expected behavior
When a client has stopped sending data, ncat should either:

  1. Exit the server and fully close the connection without waiting for the child to finish.
  2. Wait for the child to finish sending output before exiting.

Option 2 is what I would prefer, but is a bigger change than option 1. In both cases though, there is no reason for the child process to keep the socket open.

Version info (please complete the following information):

  • OS: Linux 6.8.2
  • Output of ncat --version: Ncat: Version 7.94 ( https://nmap.org/ncat )

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions