- (djm) [loginrec.c] Fix some fd leaks on error paths. ok dtucker

This commit is contained in:
Damien Miller 2011-01-02 21:43:59 +11:00
parent 928362dc03
commit 4a06f9271f
2 changed files with 11 additions and 1 deletions

View File

@ -1,3 +1,6 @@
20110102
- (djm) [loginrec.c] Fix some fd leaks on error paths. ok dtucker
20101226 20101226
- (dtucker) OpenBSD CVS Sync - (dtucker) OpenBSD CVS Sync
- djm@cvs.openbsd.org 2010/12/08 04:02:47 - djm@cvs.openbsd.org 2010/12/08 04:02:47

View File

@ -873,11 +873,13 @@ utmp_write_direct(struct logininfo *li, struct utmp *ut)
pos = (off_t)tty * sizeof(struct utmp); pos = (off_t)tty * sizeof(struct utmp);
if ((ret = lseek(fd, pos, SEEK_SET)) == -1) { if ((ret = lseek(fd, pos, SEEK_SET)) == -1) {
logit("%s: lseek: %s", __func__, strerror(errno)); logit("%s: lseek: %s", __func__, strerror(errno));
close(fd);
return (0); return (0);
} }
if (ret != pos) { if (ret != pos) {
logit("%s: Couldn't seek to tty %d slot in %s", logit("%s: Couldn't seek to tty %d slot in %s",
__func__, tty, UTMP_FILE); __func__, tty, UTMP_FILE);
close(fd);
return (0); return (0);
} }
/* /*
@ -893,16 +895,20 @@ utmp_write_direct(struct logininfo *li, struct utmp *ut)
if ((ret = lseek(fd, pos, SEEK_SET)) == -1) { if ((ret = lseek(fd, pos, SEEK_SET)) == -1) {
logit("%s: lseek: %s", __func__, strerror(errno)); logit("%s: lseek: %s", __func__, strerror(errno));
close(fd);
return (0); return (0);
} }
if (ret != pos) { if (ret != pos) {
logit("%s: Couldn't seek to tty %d slot in %s", logit("%s: Couldn't seek to tty %d slot in %s",
__func__, tty, UTMP_FILE); __func__, tty, UTMP_FILE);
close(fd);
return (0); return (0);
} }
if (atomicio(vwrite, fd, ut, sizeof(*ut)) != sizeof(*ut)) { if (atomicio(vwrite, fd, ut, sizeof(*ut)) != sizeof(*ut)) {
logit("%s: error writing %s: %s", __func__, logit("%s: error writing %s: %s", __func__,
UTMP_FILE, strerror(errno)); UTMP_FILE, strerror(errno));
close(fd);
return (0);
} }
close(fd); close(fd);
@ -1206,7 +1212,7 @@ wtmp_get_entry(struct logininfo *li)
close (fd); close (fd);
return (0); return (0);
} }
if ( wtmp_islogin(li, &ut) ) { if (wtmp_islogin(li, &ut) ) {
found = 1; found = 1;
/* /*
* We've already checked for a time in struct * We've already checked for a time in struct
@ -1502,6 +1508,7 @@ lastlog_openseek(struct logininfo *li, int *fd, int filemode)
if (lseek(*fd, offset, SEEK_SET) != offset) { if (lseek(*fd, offset, SEEK_SET) != offset) {
logit("%s: %s->lseek(): %s", __func__, logit("%s: %s->lseek(): %s", __func__,
lastlog_file, strerror(errno)); lastlog_file, strerror(errno));
close(*fd);
return (0); return (0);
} }
} }