Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20140921153403.GW21835@port70.net>
Date: Sun, 21 Sep 2014 17:34:04 +0200
From: Szabolcs Nagy <nsz@...t70.net>
To: musl@...ts.openwall.com
Subject: Re: [PATCH] fix a bug in the rand48 family of prng

* Jens Gustedt <Jens.Gustedt@...ia.fr> [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

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.