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
This commit is contained in:
Ed Schouten 2012-02-11 11:11:13 +00:00
parent 08e00a3927
commit a8f77c1f66
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=231514

View File

@ -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;