Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 1 Sep 2020 15:14:13 +0000 (UTC)
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r365043 - head/usr.sbin/pw
Message-ID:  <202009011514.081FEDW3093441@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: markj
Date: Tue Sep  1 15:14:13 2020
New Revision: 365043
URL: https://svnweb.freebsd.org/changeset/base/365043

Log:
  pw: Fix terminal handling when setting a group password.
  
  Reported by:	Coverity
  MFC after:	1 week
  Sponsored by:	NetApp, Inc.
  Sponsored by:	Klara, Inc.

Modified:
  head/usr.sbin/pw/pw_group.c

Modified: head/usr.sbin/pw/pw_group.c
==============================================================================
--- head/usr.sbin/pw/pw_group.c	Tue Sep  1 14:58:57 2020	(r365042)
+++ head/usr.sbin/pw/pw_group.c	Tue Sep  1 15:14:13 2020	(r365043)
@@ -66,13 +66,18 @@ grp_set_passwd(struct group *grp, bool update, int fd,
 	}
 	
 	if ((istty = isatty(fd))) {
-		n = t;
-		/* Disable echo */
-		n.c_lflag &= ~(ECHO);
-		tcsetattr(fd, TCSANOW, &n);
-		printf("%sassword for group %s:", update ? "New p" : "P",
-		    grp->gr_name);
-		fflush(stdout);
+		if (tcgetattr(fd, &t) == -1)
+			istty = 0;
+		else {
+			n = t;
+			/* Disable echo */
+			n.c_lflag &= ~(ECHO);
+			tcsetattr(fd, TCSANOW, &n);
+			printf("%sassword for group %s:",
+			    update ? "New p" : "P",
+			    grp->gr_name);
+			fflush(stdout);
+		}
 	}
 	b = read(fd, line, sizeof(line) - 1);
 	if (istty) {	/* Restore state */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202009011514.081FEDW3093441>