summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Johnston <markj@FreeBSD.org>2020-09-01 15:15:09 +0000
committerMark Johnston <markj@FreeBSD.org>2020-09-01 15:15:09 +0000
commitd39094af97e61b4f863744f5cf43ad37d28898c3 (patch)
tree4fc8c5f458ada6a2d0e9a4a4b7687294bf89e7d7
parent0352161ff390269df8d9a0bf9df8bf76de7e879e (diff)
downloadpw-darwin-d39094af97e61b4f863744f5cf43ad37d28898c3.tar.gz
pw-darwin-d39094af97e61b4f863744f5cf43ad37d28898c3.tar.zst
pw-darwin-d39094af97e61b4f863744f5cf43ad37d28898c3.zip
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.
-rw-r--r--pw/pw_user.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/pw/pw_user.c b/pw/pw_user.c
index cb95d45..2eec317 100644
--- a/pw/pw_user.c
+++ b/pw/pw_user.c
@@ -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!