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.
This commit is contained in:
Mark Johnston 2020-09-01 15:15:09 +00:00
parent 7a82cf511d
commit 645c2851e2

View File

@ -712,9 +712,9 @@ rmopie(char const * name)
{ {
char tmp[1014]; char tmp[1014];
FILE *fp; FILE *fp;
int fd;
size_t len; size_t len;
off_t atofs = 0; long atofs;
int fd;
if ((fd = openat(conf.rootfd, "etc/opiekeys", O_RDWR)) == -1) if ((fd = openat(conf.rootfd, "etc/opiekeys", O_RDWR)) == -1)
return; return;
@ -722,14 +722,14 @@ rmopie(char const * name)
fp = fdopen(fd, "r+"); fp = fdopen(fd, "r+");
len = strlen(name); 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]==' ') { if (strncmp(name, tmp, len) == 0 && tmp[len]==' ') {
/* Comment username out */ /* Comment username out */
if (fseek(fp, atofs, SEEK_SET) == 0) if (fseek(fp, atofs, SEEK_SET) == 0)
fwrite("#", 1, 1, fp); fwrite("#", 1, 1, fp);
break; break;
} }
atofs = ftell(fp);
} }
/* /*
* If we got an error of any sort, don't update! * If we got an error of any sort, don't update!