From stb@diesel.lassitu.de  Tue Aug 11 11:48:53 2009
Return-Path: <stb@diesel.lassitu.de>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 344AE1065673
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 11 Aug 2009 11:48:53 +0000 (UTC)
	(envelope-from stb@diesel.lassitu.de)
Received: from koef.zs64.net (koef.zs64.net [212.12.50.230])
	by mx1.freebsd.org (Postfix) with ESMTP id 96D408FC6F
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 11 Aug 2009 11:48:52 +0000 (UTC)
Received: from koef.zs64.net (koef.zs64.net [212.12.50.230])
	by koef.zs64.net (8.14.3/8.14.3) with ESMTP id n7BBRU01031517
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 11 Aug 2009 13:27:30 +0200 (CEST)
	(envelope-from stb@diesel.lassitu.de)
Received: (from root@localhost)
	by koef.zs64.net (8.14.3/8.14.3/Submit) id n7BBRUqk031516
	for FreeBSD-gnats-submit@freebsd.org; Tue, 11 Aug 2009 13:27:30 +0200 (CEST)
	(envelope-from stb@diesel.lassitu.de)
Message-Id: <200908111127.n7BBRUqk031516@koef.zs64.net>
Date: Tue, 11 Aug 2009 13:27:30 +0200 (CEST)
From: Stefan Bethke <stb@lassitu.de>
Reply-To: Stefan Bethke <stb@lassitu.de>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [patch] dialog goes into tight loop on encountering eof
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         137665
>Category:       gnu
>Synopsis:       [patch] dialog(1) goes into tight loop on encountering eof
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          suspended
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Aug 11 11:50:05 UTC 2009
>Closed-Date:    
>Last-Modified:  Sun Feb 27 22:16:31 EST 2011
>Originator:     Stefan Bethke
>Release:        FreeBSD 8.0-BETA2 amd64
>Organization:
>Environment:
System: FreeBSD diesel.lassitu.de 8.0-BETA2 FreeBSD 8.0-BETA2 #8 r195941: Wed Jul 29 15:55:32 CEST 2009 root@diesel.lassitu.de:/usr/obj/usr/src/sys/DIESEL amd64


	
>Description:
	
>How-To-Repeat:
dialog --yesno foo -1 -1 </dev/null

Other variants suffer from the same problem.  None of the invocations of
wgetch() check for error conditions, and the input loops usually terminate
only upon certain keys.  This leads to a tight loop of calling wgetch(),
which returns ERR immediately. The usual while or for look then calls
wgetch() again.

>Fix:

This patch checks for wgetch() return value of ERR, and takes the same action
as the user pressing escape.

Index: msgbox.c
===================================================================
--- msgbox.c	(revision 195941)
+++ msgbox.c	(working copy)
@@ -97,7 +97,7 @@
     display_helpline(dialog, height-1, width);
     print_button(dialog, "  OK  ", height-2, width/2-6, TRUE);
     wrefresh(dialog);
-    while (key != ESC && key != '\n' && key != ' ' && key != '\r')
+    while (key != ERR && key != ESC && key != '\n' && key != ' ' && key != '\r')
       key = wgetch(dialog);
     if (key == '\r')
       key = '\n';
Index: inputbox.c
===================================================================
--- inputbox.c	(revision 195941)
+++ inputbox.c	(working copy)
@@ -181,6 +181,9 @@
     case '?':
 	display_helpfile();
 	break;
+    case ERR:
+      key = ESC;
+      break;
     }
   }
 
Index: checklist.c
===================================================================
--- checklist.c	(revision 195941)
+++ checklist.c	(working copy)
@@ -202,6 +202,11 @@
     while (key != ESC) {
 	key = wgetch(dialog);
 	
+	if (key == ERR) {
+	    key = ESC;
+	    break;
+        }
+	
 	/* Shortcut to OK? */
 	if (toupper(key) == okButton) {
 	    if (ditems) {
Index: ui_objects.c
===================================================================
--- ui_objects.c	(revision 195941)
+++ ui_objects.c	(working copy)
@@ -666,7 +666,7 @@
 	if (!quit) key = wgetch(lo->win);
     }
 
-    if (key == ESC) {
+    if (key == ESC || key == ERR) {
 	return(SEL_ESC);
     }
     if (key == '\t') {
Index: lineedit.c
===================================================================
--- lineedit.c	(revision 195941)
+++ lineedit.c	(working copy)
@@ -66,6 +66,7 @@
       case KEY_F(1):
 	display_helpfile();
 	break;
+      case ERR:
       case TAB:
       case KEY_BTAB:
       case KEY_UP:
Index: textbox.c
===================================================================
--- textbox.c	(revision 195941)
+++ textbox.c	(working copy)
@@ -411,6 +411,7 @@
         else    /* no need to find */
           fprintf(stderr, "\a");    /* beep */
         break;
+      case ERR:
       case ESC:
         break;
     case KEY_F(1):
Index: yesno.c
===================================================================
--- yesno.c	(revision 195941)
+++ yesno.c	(working copy)
@@ -159,6 +159,9 @@
     case '?':
 	display_helpfile();
 	break;
+    case ERR:
+      key = ESC;
+      break;
     }
   }
 
Index: tree.c
===================================================================
--- tree.c	(revision 195941)
+++ tree.c	(working copy)
@@ -446,6 +446,7 @@
         if (!button)
 	  *result = scroll+choice;
         return button;
+    case ERR:
     case ESC:
         break;
     case KEY_F(1):
Index: prgbox.c
===================================================================
--- prgbox.c	(revision 195941)
+++ prgbox.c	(working copy)
@@ -136,7 +136,7 @@
     display_helpline(dialog, height-1, width);
     print_button(dialog, "  OK  ", height-2, width/2-6, TRUE);
     wrefresh(dialog);
-    while (key != ESC && key != '\n' && key != ' ' && key != '\r')
+    while (key != ERR && key != ESC && key != '\n' && key != ' ' && key != '\r')
       key = wgetch(dialog);
     if (key == '\r')
       key = '\n';
Index: menubox.c
===================================================================
--- menubox.c	(revision 195941)
+++ menubox.c	(working copy)
@@ -187,6 +187,11 @@
     while (key != ESC) {
 	key = wgetch(dialog);
 	
+	if (key == ERR) {
+	    key = ESC;
+	    break;
+        }
+	
 	/* Shortcut to OK? */
 	if (toupper(key) == okButton) {
 	    if (ditems) {
Index: radiolist.c
===================================================================
--- radiolist.c	(revision 195941)
+++ radiolist.c	(working copy)
@@ -544,7 +544,8 @@
 		key = ESC;
 		break;
 	    }
-	    
+
+        case ERR:	    
 	case ESC:
 	    rval = -1;
 	    break;


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->feedback 
State-Changed-By: eadler 
State-Changed-When: Thu Feb 24 08:11:02 EST 2011 
State-Changed-Why:  
Is this still an issue with the recent dialog update? 

http://www.freebsd.org/cgi/query-pr.cgi?pr=137665 

From: Eitan Adler <eadler@freebsd.org>
To: bug-followup@freebsd.org, stb@lassitu.de
Cc:  
Subject: Re: gnu/137665: [patch] dialog(1) goes into tight loop on
 encountering eof
Date: Sat, 26 Feb 2011 16:58:56 -0500

 I thought I closed this one already. I tested on a backported
 dialog(1) and it seems to be fixed. If you come out with a different
 result please let me know.
 
 -- 
 Eitan Adler

From: Stefan Bethke <stb@lassitu.de>
To: bug-followup@freebsd.org
Cc:  
Subject: Re: gnu/137665: [patch] dialog(1) goes into tight loop on encountering eof
Date: Sun, 27 Feb 2011 08:58:09 +0100

 On:
 # uname -a
 FreeBSD freebsd-current.lassitu.de 9.0-CURRENT FreeBSD 9.0-CURRENT #0 =
 r219066: Sun Feb 27 01:55:21 CET 2011     =
 root@freebsd-current.lassitu.de:/usr/obj/usr/src/sys/MINIMAL  amd64
 
 dialog does not go into a tight loop eating all CPU, but it still gets =
 stuck.  I believe it should take some action on encountering EOF, =
 instead of waiting for input forever.  My patch did that for the old =
 dialog, typically taking the same path as pressing ESC would.
 
 
 Stefan
 
 --=20
 Stefan Bethke <stb@lassitu.de>   Fon +49 151 14070811
 
 
 
State-Changed-From-To: feedback->suspended 
State-Changed-By: eadler 
State-Changed-When: Sun Feb 27 22:13:02 EST 2011 
State-Changed-Why:  
This is contrib software & should probably be resolved upstream. 
Also - behavior reported in PR has been fixed with recent update 

http://www.freebsd.org/cgi/query-pr.cgi?pr=137665 
>Unformatted:
