Date: Tue, 1 Sep 2020 15:15:09 +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: r365046 - head/usr.sbin/pw Message-ID: <202009011515.081FF9DX093622@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: markj Date: Tue Sep 1 15:15:09 2020 New Revision: 365046 URL: https://svnweb.freebsd.org/changeset/base/365046 Log: pw: Handle errors from ftell() when removing records from /etc/opiekeys. Reported by: Coverity MFC after: 1 week Sponsored by: NetApp, Inc. Sponsored by: Klara, Inc. Modified: head/usr.sbin/pw/pw_user.c Modified: head/usr.sbin/pw/pw_user.c ============================================================================== --- head/usr.sbin/pw/pw_user.c Tue Sep 1 15:14:51 2020 (r365045) +++ head/usr.sbin/pw/pw_user.c Tue Sep 1 15:15:09 2020 (r365046) @@ -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!
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202009011515.081FF9DX093622>