From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/6182 Path: news.gmane.org!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] fix a bug in the rand48 family of prng Date: Sun, 21 Sep 2014 17:34:04 +0200 Message-ID: <20140921153403.GW21835@port70.net> References: <1411310306.4884.188.camel@eris.loria.fr> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1411313666 10351 80.91.229.3 (21 Sep 2014 15:34:26 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 21 Sep 2014 15:34:26 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-6195-gllmg-musl=m.gmane.org@lists.openwall.com Sun Sep 21 17:34:17 2014 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1XVj9U-0008Pt-KA for gllmg-musl@plane.gmane.org; Sun, 21 Sep 2014 17:34:16 +0200 Original-Received: (qmail 29950 invoked by uid 550); 21 Sep 2014 15:34:16 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 29942 invoked from network); 21 Sep 2014 15:34:15 -0000 Mail-Followup-To: musl@lists.openwall.com Content-Disposition: inline In-Reply-To: <1411310306.4884.188.camel@eris.loria.fr> User-Agent: Mutt/1.5.23 (2014-03-12) Xref: news.gmane.org gmane.linux.lib.musl.general:6182 Archived-At: * Jens Gustedt [2014-09-21 16:39:34 +0200]: > > This fixes a bug found by Nadav Har'El, who observed that musl was giving > different prn sequences than other systems, even if seeded with the same > value. > > The problem with something like > > a = lc[0] | lc[1]<<16 | lc[2]+0ULL<<32; > > where lc[1] is an unsigned short and int is 32bit is the following > > (1) lc[1] is promoted to int > (2) the left shift 16 is performed on int > the fix looks ok, but i'm not clear on why it breaks in practice (i know it's ub, but gcc used to handle such shifts "as expected" the linux kernel is full of them and c++14 allows this and there is a dr to change the semantics for c too http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_463.htm ) > this is UB if bit 15 is set in lc[1], since it moves a 1 into the sign > bit. > > In particular, bit 15 *is* 1 for the default multplicator A as defined by POSIX. > > (On systems with 16 bit int all of this has UB anyhow.) posix requires at least 32 bit int