svn commit: r365454 - stable/12/usr.sbin/pw

Mark Johnston markj at FreeBSD.org
Tue Sep 8 12:38:36 UTC 2020


Author: markj
Date: Tue Sep  8 12:38:34 2020
New Revision: 365454
URL: https://svnweb.freebsd.org/changeset/base/365454

Log:
  MFC r365043-r365046:
  pw: Coverity fixes.

Modified:
  stable/12/usr.sbin/pw/pw_group.c
  stable/12/usr.sbin/pw/pw_user.c
  stable/12/usr.sbin/pw/rm_r.c
  stable/12/usr.sbin/pw/strtounum.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/usr.sbin/pw/pw_group.c
==============================================================================
--- stable/12/usr.sbin/pw/pw_group.c	Tue Sep  8 12:37:46 2020	(r365453)
+++ stable/12/usr.sbin/pw/pw_group.c	Tue Sep  8 12:38:34 2020	(r365454)
@@ -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 */

Modified: stable/12/usr.sbin/pw/pw_user.c
==============================================================================
--- stable/12/usr.sbin/pw/pw_user.c	Tue Sep  8 12:37:46 2020	(r365453)
+++ stable/12/usr.sbin/pw/pw_user.c	Tue Sep  8 12:38:34 2020	(r365454)
@@ -712,24 +712,24 @@ rmopie(char const * name)
 {
 	char tmp[1014];
 	FILE *fp;
-	int fd;
 	size_t len;
-	off_t	atofs = 0;
-	
+	long atofs;
+	int fd;
+
 	if ((fd = openat(conf.rootfd, "etc/opiekeys", O_RDWR)) == -1)
 		return;
 
 	fp = fdopen(fd, "r+");
 	len = strlen(name);
 
-	while (fgets(tmp, sizeof(tmp), fp) != NULL) {
+	for (atofs = 0; fgets(tmp, sizeof(tmp), fp) != NULL && atofs >= 0;
+	    atofs = ftell(fp)) {
 		if (strncmp(name, tmp, len) == 0 && tmp[len]==' ') {
 			/* Comment username out */
 			if (fseek(fp, atofs, SEEK_SET) == 0)
 				fwrite("#", 1, 1, fp);
 			break;
 		}
-		atofs = ftell(fp);
 	}
 	/*
 	 * If we got an error of any sort, don't update!

Modified: stable/12/usr.sbin/pw/rm_r.c
==============================================================================
--- stable/12/usr.sbin/pw/rm_r.c	Tue Sep  8 12:37:46 2020	(r365453)
+++ stable/12/usr.sbin/pw/rm_r.c	Tue Sep  8 12:38:34 2020	(r365454)
@@ -57,6 +57,10 @@ rm_r(int rootfd, const char *path, uid_t uid)
 	}
 
 	d = fdopendir(dirfd);
+	if (d == NULL) {
+		(void)close(dirfd);
+		return;
+	}
 	while ((e = readdir(d)) != NULL) {
 		if (strcmp(e->d_name, ".") == 0 || strcmp(e->d_name, "..") == 0)
 			continue;

Modified: stable/12/usr.sbin/pw/strtounum.c
==============================================================================
--- stable/12/usr.sbin/pw/strtounum.c	Tue Sep  8 12:37:46 2020	(r365453)
+++ stable/12/usr.sbin/pw/strtounum.c	Tue Sep  8 12:38:34 2020	(r365454)
@@ -44,28 +44,24 @@ strtounum(const char * __restrict np, uintmax_t minval
 	*errpp = NULL;
 	if (minval > maxval) {
 		errno = EINVAL;
-		if (errpp != NULL)
-			*errpp = "invalid";
+		*errpp = "invalid";
 		return (0);
 	}
 	errno = 0;
 	ret = strtoumax(np, &endp, 10);
 	if (endp == np || *endp != '\0') {
 		errno = EINVAL;
-		if (errpp != NULL)
-			*errpp = "invalid";
+		*errpp = "invalid";
 		return (0);
 	}
 	if (ret < minval) {
 		errno = ERANGE;
-		if (errpp != NULL)
-			*errpp = "too small";
+		*errpp = "too small";
 		return (0);
 	}
 	if (errno == ERANGE || ret > maxval) {
 		errno = ERANGE;
-		if (errpp != NULL)
-			*errpp = "too large";
+		*errpp = "too large";
 		return (0);
 	}
 	return (ret);


More information about the svn-src-stable mailing list