Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date: Fri, 9 Dec 2016 07:16:42 +0100
From: Ed Schouten <>
Subject: jrand48(): missing cast to int32_t?

Hi there,

According to POSIX, jrand48() is supposed to return a value between
[-2^31, 2^31). Musl's version of jrand48() is implemented as follows:

long jrand48(unsigned short s[3])
        return __rand48_step(s, __seed48+3) >> 16;

Notice that the function only uses simple bit shifting and its return
type is long, meaning that on 64-bit systems, this implementation may
actually return a value between [0, 2^32).

For some reason, FreeBSD had the same bug. By adding a cast to
int32_t, its implementation now returns the same sequence of
pseudo-random numbers as macOS, Solaris, glibc, etc.

Musl's version should likely be changed to this:

long jrand48(unsigned short s[3])
        return (int32_t)(__rand48_step(s, __seed48+3) >> 16);

Best regards,
Ed Schouten <>
Nuxi, 's-Hertogenbosch, the Netherlands
KvK-nr.: 62051717

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.