[PATCH] Check tcgetattr return value in init/init.c
Timur R. Mustafin
Timur.R.Mustafin at mcst.ru
Mon Dec 2 11:14:09 UTC 2019
Hello, busybox developers!
I found uninitialized variable use in /set_sane_term()/. It calls
/tcgetattr()/ function that should set /&tty /structure, but
/tcgetattr()/ can fail. During a fail /&tty/ structure stay
uninitialized. Patch checks return values of /tcgetattr()/,
/tcsetattr()/ and makes /set_sane_term()/ function error-returning.
Regards,
Timur.
diff --git a/init/init.c b/init/init.c
index 87086b4..a837652 100644
--- a/init/init.c
+++ b/init/init.c
@@ -343,11 +343,13 @@ static void console_init(void)
/* Set terminal settings to reasonable defaults.
* NB: careful, we can be called after vfork! */
-static void set_sane_term(void)
+static int set_sane_term(void)
{
struct termios tty;
- tcgetattr(STDIN_FILENO, &tty);
+ /* tcgetattr() returns 0 on success, -1 on failure */
+ if (tcgetattr(STDIN_FILENO, &tty) == -1)
+ return 0;
/* set control chars */
tty.c_cc[VINTR] = 3; /* C-c */
@@ -381,7 +383,8 @@ static void set_sane_term(void)
/* local modes */
tty.c_lflag = ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHOCTL |
ECHOKE | IEXTEN;
- tcsetattr_stdin_TCSANOW(&tty);
+ /* tcsetattr() returns 0 on success, -1 on failure */
+ return !tcsetattr_stdin_TCSANOW(&tty);
}
/* Open the new terminal device.
@@ -405,8 +408,7 @@ static int open_stdio_to_tty(const char* tty_name)
dup2(STDIN_FILENO, STDOUT_FILENO);
dup2(STDIN_FILENO, STDERR_FILENO);
}
- set_sane_term();
- return 1; /* success */
+ return set_sane_term();
}
static void reset_sighandlers_and_unblock_sigs(void)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20191202/3910523a/attachment.html>
More information about the busybox
mailing list