From owner-svn-src-stable-9@FreeBSD.ORG Fri Mar 2 21:38:27 2012 Return-Path: Delivered-To: svn-src-stable-9@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 838641065672; Fri, 2 Mar 2012 21:38:27 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 6F6648FC15; Fri, 2 Mar 2012 21:38:27 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q22LcRxR048505; Fri, 2 Mar 2012 21:38:27 GMT (envelope-from ed@svn.freebsd.org) Received: (from ed@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q22LcRZ2048502; Fri, 2 Mar 2012 21:38:27 GMT (envelope-from ed@svn.freebsd.org) Message-Id: <201203022138.q22LcRZ2048502@svn.freebsd.org> From: Ed Schouten Date: Fri, 2 Mar 2012 21:38:27 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r232408 - stable/9/lib/libc/gen X-BeenThere: svn-src-stable-9@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for only the 9-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 02 Mar 2012 21:38:27 -0000 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;