Bug 19302 - read("/proc/net/tcp") fails with buffer <= 128 bytes.
read("/proc/net/tcp") fails with buffer <= 128 bytes.
Status: CLOSED CURRENTRELEASE
Product: Red Hat Linux
Classification: Retired
Component: kernel (Show other bugs)
7.0
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Arjan van de Ven
Brian Brock
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2000-10-17 23:13 EDT by Sam Varshavchik
Modified: 2007-04-18 12:29 EDT (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2002-12-15 23:08:44 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
An example (2.89 KB, text/plain)
2000-10-17 23:14 EDT, Sam Varshavchik
no flags Details

  None (edit)
Description Sam Varshavchik 2000-10-17 23:13:54 EDT
Make sure the machine has at least a few dozen TCP sockets open:

dd if=/proc/net/tcp bs=129          -- shows all open TCP sockets

dd if=/proc/net/tcp bs=128          -- does not

I stumbled across this when I tried to run less on /proc/net/tcp, and got
far fewer sockets than I knew I had. After tracking down what was going on,
I discovered that if you keep doing a read on /proc/net/tcp with a buffer
size of 128 bytes or less, you're going to get a premature EOF indication.
Comment 1 Sam Varshavchik 2000-10-17 23:14:21 EDT
Created attachment 4309 [details]
An example
Comment 2 Arjan van de Ven 2000-10-18 13:27:34 EDT
This is an off-by-one error; the patch below fixes it for me.

--- linux/net/ipv4/proc.c.org   Wed Oct 18 18:27:26 2000
+++ linux/net/ipv4/proc.c       Wed Oct 18 19:27:58 2000
@@ -186,7 +186,7 @@
                                if (req->sk)
                                        continue;
                                pos += 128;
-                               if (pos < offset)
+                               if (pos <= offset)
                                        continue;
                                get__openreq(sp, req, tmpbuf, i);
                                len += sprintf(buffer+len, "%-127s\n", tmpbuf);
@@ -196,7 +196,7 @@
                }

                pos += 128;
-               if (pos < offset)
+               if (pos <= offset)
                        goto next;

                get__sock(sp, tmpbuf, i, format);

Comment 3 Alan Cox 2002-12-15 23:08:44 EST
Long fixed should have been closed

Note You need to log in before you can comment on or make changes to this bug.