From owner-svn-src-head@FreeBSD.ORG Tue Oct 9 14:25:15 2012 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 9594CCE2; Tue, 9 Oct 2012 14:25:15 +0000 (UTC) (envelope-from eadler@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 7D8768FC18; Tue, 9 Oct 2012 14:25:15 +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 q99EPFJT020790; Tue, 9 Oct 2012 14:25:15 GMT (envelope-from eadler@svn.freebsd.org) Received: (from eadler@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q99EPFS6020787; Tue, 9 Oct 2012 14:25:15 GMT (envelope-from eadler@svn.freebsd.org) Message-Id: <201210091425.q99EPFS6020787@svn.freebsd.org> From: Eitan Adler Date: Tue, 9 Oct 2012 14:25:15 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r241373 - head/lib/libc/stdlib X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Oct 2012 14:25:15 -0000 Author: eadler Date: Tue Oct 9 14:25:14 2012 New Revision: 241373 URL: http://svn.freebsd.org/changeset/base/241373 Log: Remove undefined behavior from sranddev() and srandomdev(). This doesn't actually work with any modern C compiler: In particular, both clang and modern gcc verisons silently elide any xor operation with 'junk'. Approved by: secteam MFC after: 3 days Modified: head/lib/libc/stdlib/rand.c head/lib/libc/stdlib/random.c Modified: head/lib/libc/stdlib/rand.c ============================================================================== --- head/lib/libc/stdlib/rand.c Tue Oct 9 13:21:08 2012 (r241372) +++ head/lib/libc/stdlib/rand.c Tue Oct 9 14:25:14 2012 (r241373) @@ -130,10 +130,9 @@ sranddev() if (!done) { struct timeval tv; - unsigned long junk; gettimeofday(&tv, NULL); - srand((getpid() << 16) ^ tv.tv_sec ^ tv.tv_usec ^ junk); + srand((getpid() << 16) ^ tv.tv_sec ^ tv.tv_usec); } } Modified: head/lib/libc/stdlib/random.c ============================================================================== --- head/lib/libc/stdlib/random.c Tue Oct 9 13:21:08 2012 (r241372) +++ head/lib/libc/stdlib/random.c Tue Oct 9 14:25:14 2012 (r241373) @@ -312,10 +312,9 @@ srandomdev(void) if (!done) { struct timeval tv; - volatile unsigned long junk; gettimeofday(&tv, NULL); - srandom((getpid() << 16) ^ tv.tv_sec ^ tv.tv_usec ^ junk); + srandom((getpid() << 16) ^ tv.tv_sec ^ tv.tv_usec); return; }