diff options
author | ed <ed@FreeBSD.org> | 2012-02-11 11:11:13 +0000 |
---|---|---|
committer | ed <ed@FreeBSD.org> | 2012-02-11 11:11:13 +0000 |
commit | aa3326a5354b16c7d109738ad8a4d534127d79b9 (patch) | |
tree | 2fe53409a0cdb5c96c178c43b305e16b411dd147 /lib | |
parent | 0e68cca864978c179a24279a53f66a77da2f4b6e (diff) | |
download | FreeBSD-src-aa3326a5354b16c7d109738ad8a4d534127d79b9.zip FreeBSD-src-aa3326a5354b16c7d109738ad8a4d534127d79b9.tar.gz |
Set read buffer size to multiple of sizeof(struct futx).
If the utmpx database gets updated while an application is reading it,
there is a chance the reading application processes partially
overwritten entries. To solve this, make sure we always read a multiple
of sizeof(struct futx) at a time.
MFC after: 2 weeks
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/gen/getutxent.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/lib/libc/gen/getutxent.c b/lib/libc/gen/getutxent.c index 556df56..4e60868 100644 --- a/lib/libc/gen/getutxent.c +++ b/lib/libc/gen/getutxent.c @@ -70,13 +70,18 @@ setutxdb(int db, const char *file) if (uf == NULL) return (-1); - /* Safety check: never use broken files. */ - if (db != UTXDB_LOG && _fstat(fileno(uf), &sb) != -1 && - sb.st_size % sizeof(struct futx) != 0) { - fclose(uf); - uf = NULL; - errno = EFTYPE; - return (-1); + if (db != UTXDB_LOG) { + /* Safety check: never use broken files. */ + if (_fstat(fileno(uf), &sb) != -1 && + sb.st_size % sizeof(struct futx) != 0) { + fclose(uf); + uf = NULL; + errno = EFTYPE; + return (-1); + } + /* Prevent reading of partial records. */ + (void)setvbuf(uf, NULL, _IOFBF, + rounddown(BUFSIZ, sizeof(struct futx))); } udb = db; |