#1075806 xclip: enters infinite read(4, ..., 4096) = -1 EISDIR error loop when given a directory

Package:
xclip
Source:
xclip
Description:
command line interface to X selections
Submitter:
наб
Date:
2024-12-30 17:36:06 UTC
Severity:
normal
Tags:
#1075806#5
Date:
2024-07-05 13:20:07 UTC
From:
To:
Dear Maintainer,

I gave xclip a directory instead of a similarly-named file by accident.
Instead of erroring it looped forever.

strace:
	recvmsg(3, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="\1\0\7\0\0\0\0\0\364\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", iov_len=4096}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 32
	recvmsg(3, {msg_namelen=0}, 0)          = -1 EAGAIN (Resource temporarily unavailable)
	recvmsg(3, {msg_namelen=0}, 0)          = -1 EAGAIN (Resource temporarily unavailable)
	openat(AT_FDCWD, ".", O_RDONLY)         = 4
	newfstatat(4, "", {st_mode=S_IFDIR|0755, st_size=4096, ...}, AT_EMPTY_PATH) = 0
	read(4, 0x566b72a0, 4096)               = -1 EISDIR (Is a directory)
	read(4, 0x566b72a0, 4096)               = -1 EISDIR (Is a directory)
and this repeats ad infinitum.

ltrace:
	XSelectInput(0x55b45a3f0870, 0x380001, 0x400000, 0xeff5)                   = 1
	malloc(16)                                                                 = 0x55b45a4011e0
	fopen(".", "r")                                                            = 0x55b45a3f1c90
	feof(0x55b45a3f1c90)                                                       = 0
	fread(0x55b45a4011e0, 1, 16, 0x55b45a3f1c90)                               = 0
	feof(0x55b45a3f1c90)                                                       = 0
	fread(0x55b45a4011e0, 1, 16, 0x55b45a3f1c90)                               = 0
and the last two repeat ad infinitum.

Probably want to check ferror too.

Best,

#1075806#10
Date:
2024-07-05 13:52:24 UTC
From:
To:
See attached patch, which fixes the way xclip uses stdio:
  $ ./xclip < .
  ./xclip: (stdin): Is a directory
  $ ./xclip  .
  ./xclip: .: Is a directory

Best,

#1075806#19
Date:
2024-07-05 19:44:06 UTC
From:
To:
Didn't attach a patch. Good, because I found a bug. Attaching fixed.