Skip to content

cat Unix Domain Socket “Connect” Behavior #9751

@sylvestre

Description

@sylvestre

Component

cat

Description

uutils cat treats files whose paths are Unix domain sockets as clients, connecting to them via connect() and reading data; GNU cat only performs open() and does not actively connect to such sockets (usually returning an error directly).

Test / Reproduction Steps

``
import socket
import os

sock_path = "/tmp/tmp.sock"

if os.path.exists(sock_path):
os.remove(sock_path)

with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as server:
server.bind(sock_path)
server.listen(1)
print(f"Listening on {sock_path}...")

while True:
    conn, _ = server.accept()
    try:
        conn.sendall(b"Hello Sock!\n")
    finally:
        conn.close()

```bash
$ cat /tmp/tmp.sock                                                 
cat: /tmp/tmp.sock: No such device or address
$ ./target/release/coreutils cat /tmp/tmp.sock   
Hello Sock!

  • GNU: No such device or address
  • uutils: connect success and print output from socket

Impact

cat changes from "passively reading files" to "actively connecting to local servers", which may trigger server-side side effects or leak data (e.g., accidental connection to privileged Unix sockets) and cause hangs or blocks.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions