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

7.94/95 break SCTP listening when stdin=/dev/null #2829

Open
edsantiago opened this issue May 2, 2024 · 1 comment
Open

7.94/95 break SCTP listening when stdin=/dev/null #2829

edsantiago opened this issue May 2, 2024 · 1 comment
Labels

Comments

@edsantiago
Copy link

Describe the bug
Identical to #2685, except with SCTP

To Reproduce
Terminal 1:

# modprobe sctp
# nc -4 --sctp -l -p 5000 </dev/null

Terminal 2:

# echo test | nc -4 --sctp 127.0.0.1 5000

Expected behavior
Expect terminal 1 to see test. (Removing the redirection makes it work)

Version info (please complete the following information):

  • OS: Fedora 39
  • Output of ncat --version: Ncat: Version 7.95
@Luap99
Copy link

Luap99 commented May 3, 2024

strace output with /dev/null on stdin

accept(3, {sa_family=AF_INET, sin_port=htons(44148), sin_addr=inet_addr("127.0.0.1")}, [128 => 16]) = 4
close(3)                                = 0
fcntl(4, F_GETFL)                       = 0x2 (flags O_RDWR)
fcntl(4, F_SETFL, O_RDWR|O_NONBLOCK)    = 0
pselect6(5, [0 4], [], NULL, NULL, NULL) = 2 (in [0 4])
read(0, "", 8192)                       = 0
exit_group(0)                           = ?
+++ exited with 0 +++

with /dev/zero on stdin:

...
accept(3, {sa_family=AF_INET, sin_port=htons(54661), sin_addr=inet_addr("127.0.0.1")}, [128 => 16]) = 4
close(3)                                = 0
fcntl(4, F_GETFL)                       = 0x2 (flags O_RDWR)
fcntl(4, F_SETFL, O_RDWR|O_NONBLOCK)    = 0
pselect6(5, [0 4], [], NULL, NULL, NULL) = 2 (in [0 4])
read(0, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 8192) = 8192
fcntl(4, F_GETFL)                       = 0x802 (flags O_RDWR|O_NONBLOCK)
fcntl(4, F_SETFL, O_RDWR)               = 0
sendto(4, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 8192, 0, NULL, 0) = -1 EPIPE (Broken pipe)
--- SIGPIPE {si_signo=SIGPIPE, si_code=SI_USER, si_pid=74438, si_uid=1000} ---
fcntl(4, F_GETFL)                       = 0x2 (flags O_RDWR)
fcntl(4, F_SETFL, O_RDWR|O_NONBLOCK)    = 0
close(4)                                = 0
read(0, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 8192) = 8192
exit_group(0)             

and when it is attached to the terminal (working):

accept(3, {sa_family=AF_INET, sin_port=htons(32795), sin_addr=inet_addr("127.0.0.1")}, [128 => 16]) = 4
close(3)                                = 0
fcntl(4, F_GETFL)                       = 0x2 (flags O_RDWR)
fcntl(4, F_SETFL, O_RDWR|O_NONBLOCK)    = 0
pselect6(5, [0 4], [], NULL, NULL, NULL) = 1 (in [4])
recvfrom(4, "test\n", 8192, 0, NULL, NULL) = 5
write(1, "test\n", 5test
)                   = 5
pselect6(5, [0 4], [], NULL, NULL, NULL) = 1 (in [4])
recvfrom(4, "", 8192, 0, NULL, NULL)    = 0
close(4)                                = 0
exit_group(0)                           = ?
+++ exited with 0 +++

So if there is data on stdin (or it was closed) it will exit right away before printing the data it got.

Luap99 added a commit to Luap99/netavark that referenced this issue May 3, 2024
nmap-ncat seem to have weird bugs in that the received data is only
printed on stdout when there is a no data on stdin, not stdin because
the returns EOF when it gets read and if there is any data then ncat
fails as well as it cannot write it to the remote[1]...

So just try to emulate like how it works in a terminal by creating an
anonymous pipe that contains no data so ncat is happy and prints our
test string as expected.

[1] nmap/nmap#2829

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
Luap99 added a commit to Luap99/netavark that referenced this issue May 7, 2024
nmap-ncat seem to have weird bugs in that the received data is only
printed on stdout when there is a no data on stdin, not stdin because
the returns EOF when it gets read and if there is any data then ncat
fails as well as it cannot write it to the remote[1]...

So just try to emulate like how it works in a terminal by creating an
anonymous pipe that contains no data so ncat is happy and prints our
test string as expected.

[1] nmap/nmap#2829

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants