Date: Fri, 2 Mar 2012 21:38:27 +0000 (UTC) From: Ed Schouten <ed@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r232408 - stable/9/lib/libc/gen Message-ID: <201203022138.q22LcRZ2048502@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ed Date: Fri Mar 2 21:38:27 2012 New Revision: 232408 URL: http://svn.freebsd.org/changeset/base/232408 Log: MFC r231514: 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. Modified: stable/9/lib/libc/gen/getutxent.c Directory Properties: stable/9/lib/libc/ (props changed) Modified: stable/9/lib/libc/gen/getutxent.c ============================================================================== --- stable/9/lib/libc/gen/getutxent.c Fri Mar 2 21:38:06 2012 (r232407) +++ stable/9/lib/libc/gen/getutxent.c Fri Mar 2 21:38:27 2012 (r232408) @@ -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;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201203022138.q22LcRZ2048502>