NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
bin/55551: [PATCH] script(1): Minor modification to tcgetattr error handling.
>Number: 55551
>Category: bin
>Synopsis: [PATCH] script(1): Minor modification to tcgetattr error handling.
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: bin-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sat Aug 08 14:40:00 +0000 2020
>Originator: Soumendra Ganguly
>Release: 9.0
>Organization:
Texas A&M University
>Environment:
NetBSD localhost 9.0 NetBSD 9.0 (GENERIC) #0: Fri Feb 14 00:06:28 UTC 2020 mkrepro%mkrepro.NetBSD.org@localhost:/usr/src/sys/arch/amd64/compile/GENERIC amd64
>Description:
Upon more testing, it was found that the way tcgetattr is called in script(1), it cannot fail with errno == EBADF under normal circumstances (*): script(1) of course does not close its own stdin/stdout voluntarily mid execution.
(*) The only way I was able to force an EBADF was by using
[ p close(1) ] in gdb. Therefore, the EBADF error handling is not removed by this patch, it is only changed to errno != ENOTTY.
>How-To-Repeat:
There is no problem. Only minor restructuring is being done.
>Fix:
--- src/usr.bin/script/script.c 2020-08-08 04:42:52.154774132 -0500
+++ script.c 2020-08-08 04:58:28.624464431 -0500
@@ -158,16 +158,10 @@
if (tcgetattr(STDIN_FILENO, &tt) == -1 ||
ioctl(STDIN_FILENO, TIOCGWINSZ, &win) == -1) {
- switch (errno) {
- case ENOTTY:
- if (openpty(&master, &slave, NULL, NULL, NULL) == -1)
- err(EXIT_FAILURE, "openpty");
- break;
- case EBADF:
- err(EXIT_FAILURE, "%d not valid fd", STDIN_FILENO);
- default: /* errno == EFAULT or EINVAL for ioctl. Not reached in practice. */
- err(EXIT_FAILURE, "ioctl");
- }
+ if (errno != ENOTTY) /* For debugger. */
+ err(EXIT_FAILURE, "tcgetattr/ioctl");
+ if (openpty(&master, &slave, NULL, NULL, NULL) == -1)
+ err(EXIT_FAILURE, "openpty");
} else {
if (openpty(&master, &slave, NULL, &tt, &win) == -1)
err(EXIT_FAILURE, "openpty");
@@ -383,9 +377,8 @@
struct termios traw;
if (tcgetattr(STDOUT_FILENO, &tt) == -1) {
- if (errno == EBADF)
- err(EXIT_FAILURE, "%d not valid fd", STDOUT_FILENO);
- /* errno == ENOTTY */
+ if (errno != ENOTTY) /* For debugger. */
+ err(EXIT_FAILURE, "tcgetattr");
return;
}
isterm = 1;
Home |
Main Index |
Thread Index |
Old Index