netcat hangs when tries to process input of a shell script as UDP server
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
netcat (Debian) |
New
|
Unknown
|
|||
netcat (Ubuntu) |
New
|
Undecided
|
Unassigned |
Bug Description
Package: netcat
Version: 1.10-33
Netcat hangs when it acts as UDP server and receives the input on a
shell script and tries to process it.
This is the simplest bash script to test it:
$ cat test.sh
#! /bin/bash
read v
echo $v
Using netcat:
Server: nc -u -l -p 9999 -e /home/user/test.sh
Client: printf "%b" "something\n" | nc -u localhost 9999
Log: sudo /usr/sbin/tcpdump -s 0 -xX udp -i lo
16:45:07.704270 IP localhost.32808 > localhost.9999: UDP, length 10
0x0000: 4500 0026 2889 4000 4011 143c 7f00 0001 E..&(.@.@..<....
0x0010: 7f00 0001 8028 270f 0012 fe25 736f 6d65 .....('....%some
0x0020: 7468 696e 670a thing.
As you can see, there is no response from server.
However, we get the expected result trying the same test with netcat6,
version 1.0-1.
Server: nc6 -u -l -p 9999 -e /home/user/test.sh
Client: printf "%b" "something\n" | nc6 -u localhost 9999
Log: sudo /usr/sbin/tcpdump -s 0 -xX udp -i lo
16:45:29.576650 IP localhost.32808 > localhost.9999: UDP, length 10
0x0000: 4500 0026 3de5 4000 4011 fedf 7f00 0001 E..&=.@.@.......
0x0010: 7f00 0001 8028 270f 0012 fe25 736f 6d65 .....('....%some
0x0020: 7468 696e 670a thing.
16:45:29.580246 IP localhost.9999 > localhost.32808: UDP, length 10
0x0000: 4500 0026 3de5 4000 4011 fedf 7f00 0001 E..&=.@.@.......
0x0010: 7f00 0001 270f 8028 0012 fe25 736f 6d65 ....'..(...%some
0x0020: 7468 696e 670a
This is the summarized strace of the netcat server that is hanging:
$ strace nc -u -l -p 9999 -e /home/user/test.sh
...
bind(3, {sa_family=AF_INET, sin_port=
rt_sigaction(
alarm(0) = 0
rt_sigprocmask(
recvfrom(3,
"something\n", 8192, MSG_PEEK, {sa_family=AF_INET, sin_port=
rt_sigaction(
alarm(0) = 0
connect(3, {sa_family=AF_INET, sin_port=
getsockname(3, {sa_family=AF_INET, sin_port=
dup2(3, 0) = 0
...
ioctl(0, SNDCTL_TMR_TIMEBASE or TCGETS, 0xbff0c948) = -1 EINVAL (Invalid argument)
_llseek(0, 0, 0xbff0c9b0, SEEK_CUR) = -1 ESPIPE (Illegal seek)
read(0, "s", 1) = 1
read(0,
As you can see, it reads first 's' char from string "something" and remains
blocked forever.
tags: | added: udd-find |
Changed in netcat (Debian): | |
status: | Unknown → New |
I can confirm this bug persist in natty netcat-traditional 1.10-38.