netcat hangs when tries to process input of a shell script as UDP server

Bug #277428 reported by aicastell@circontrol.com on 2008-10-03
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
netcat (Debian)
New
Unknown
netcat (Ubuntu)
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=htons(9999), sin_addr=inet_addr("0.0.0.0")}, 16) = 0
rt_sigaction(SIGALRM, {SIG_IGN}, {SIG_DFL}, 8) = 0
alarm(0) = 0
rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
recvfrom(3,
"something\n", 8192, MSG_PEEK, {sa_family=AF_INET, sin_port=htons(32810), sin_addr=inet_addr("127.0.0.1")}, [16]) = 10
rt_sigaction(SIGALRM, {SIG_IGN}, {SIG_IGN}, 8) = 0
alarm(0) = 0
connect(3, {sa_family=AF_INET, sin_port=htons(32810), sin_addr=inet_addr("127.0.0.1")}, 16) = 0
getsockname(3, {sa_family=AF_INET, sin_port=htons(9999), sin_addr=inet_addr("127.0.0.1")}, [16]) = 0
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
Revision history for this message
周成瑞 (e93b5ae3) wrote :

I can confirm this bug persist in natty netcat-traditional 1.10-38.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.