[PATCH] Check if we are on tty before initializing curses

Stanislav Ochotnicky sochotnicky at redhat.com
Fri Feb 14 12:58:38 CET 2014


    When we did not have a ttyname we just used stdin/out without checking if
    it's a proper TTY or a pipe. In some cases this can cause endless loop or
    escape seqeunces on the terminal.

    This commit changes behaviour so that if stdin/out is not tty and no ttyname
    is specified we error-out with errno set to ENOTTY

    * pinentry/pinentry-curses.c
---
 pinentry/pinentry-curses.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/pinentry/pinentry-curses.c b/pinentry/pinentry-curses.c
index 58da255..4fc8bc4 100644
--- a/pinentry/pinentry-curses.c
+++ b/pinentry/pinentry-curses.c
@@ -752,6 +752,11 @@ dialog_run (pinentry_t pinentry, const char *tty_name, const char *tty_type)
     {
       if (!init_screen)
 	{
+          if (!(isatty(fileno(stdin)) && isatty(fileno(stdout))))
+            {
+              errno = ENOTTY;
+              return -1;
+            }
 	  init_screen = 1;
 	  initscr ();
 	}
-- 
1.8.3.2




More information about the Gnupg-devel mailing list