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 */
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "[email protected]"

Reply via email to