summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Johnston <markj@FreeBSD.org>2020-09-01 15:14:13 +0000
committerMark Johnston <markj@FreeBSD.org>2020-09-01 15:14:13 +0000
commitabe4cfb72aae79bc01f624c9b75e5e2c048e17be (patch)
tree1e166b5c00a98e1604961a1ad8b1d191515eda81
parentbd97bd394db403e3bfef3cfcede416d81f93b349 (diff)
downloadpw-darwin-abe4cfb72aae79bc01f624c9b75e5e2c048e17be.tar.gz
pw-darwin-abe4cfb72aae79bc01f624c9b75e5e2c048e17be.tar.zst
pw-darwin-abe4cfb72aae79bc01f624c9b75e5e2c048e17be.zip
pw: Fix terminal handling when setting a group password.
Reported by: Coverity MFC after: 1 week Sponsored by: NetApp, Inc. Sponsored by: Klara, Inc.
-rw-r--r--pw/pw_group.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/pw/pw_group.c b/pw/pw_group.c
index dd65062..a294d4e 100644
--- a/pw/pw_group.c
+++ b/pw/pw_group.c
@@ -66,13 +66,18 @@ grp_set_passwd(struct group *grp, bool update, int fd, bool precrypted)
}
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 */