From: Goldwyn Rodrigues Date: Wed, 6 Dec 2023 19:19:17 +0000 (-0600) Subject: more: exit if POLLHUP or POLLERR on stdin is received X-Git-Tag: v2.40-rc1~121 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9be4122b1d8c1c2b8eb270998838c73bae7ff2ff;p=thirdparty%2Futil-linux.git more: exit if POLLHUP or POLLERR on stdin is received more command continues to run in case stdin have closed the file and it takes 100% of CPU. This is because revents on stdin send POLLIN | POLLHUP | POLLERR once stdin is closed. more receives it even though it is not requested in events. This is common Linux behaviour to never mask out POLLHUP or POLLERR. The loop in more_key_command() runs infinitely because more_poll() returns 0 and read_command() reads 0 bytes. Steps to reproduce: 1. Setup /etc/systemd/logind.conf with KillUserProcesses=no 2. Add config "Defaults use_pty" in /etc/sudoers 3. Start an ssh session to the machine 4. # sudo su - 5. # more 6. kill the parent ssh process, say close the tab At this time "more" runs with 100% CPU utilization. Signed-off-by: Goldwyn Rodrigues --- diff --git a/text-utils/more.c b/text-utils/more.c index d4db3d5eb9..6ab9dfe403 100644 --- a/text-utils/more.c +++ b/text-utils/more.c @@ -1392,6 +1392,11 @@ static int more_poll(struct more_control *ctl, int timeout) abort(); } } + + /* Check for POLLERR or POLLHUP in revents */ + if (pfd[1].revents & (POLLHUP | POLLERR)) + more_exit(ctl); + if (pfd[1].revents == 0) return 1; return 0;