[lxc-devel] [PATCH 11/17] Use srand/rand instead of initstate/random
Stéphane Graber
stgraber at ubuntu.com
Mon Aug 19 12:11:15 UTC 2013
On Fri, Aug 16, 2013 at 05:25:34PM +0100, Daniel P. Berrange wrote:
> On Fri, Aug 16, 2013 at 06:01:25PM +0200, Stéphane Graber wrote:
> > On Fri, Aug 16, 2013 at 10:36:58AM -0500, Serge Hallyn wrote:
> > > Quoting Stéphane Graber (stgraber at ubuntu.com):
> > > > initstate/random doesn't work on bionic, srand/rand works on everything,
> > > > so let's use that.
> > >
> > > Is rand_r available on bionic?
> > >
> > > rand() isn't thread-safe.
> >
> > Unfortunately no, I actually don't think Bionic has any of the _r
> > functions.
> >
> > Is it actually a problem in this case? It looks like the worst that
> > could happen is that the random number generator gets re-seeded from
> > urandom between two calls, which would just make it even more random,
> > no?
>
> I don't think that's a safe assumption. You could have an rand()
> call overlap with a srand() call, causing rand() to access invalid
> state which may cause it to return a non-random number.
>
> Daniel
Hmm, fair enough.
I'll add an extra configure.ac check for rand_r, so that we use that if
available and only do the srand() + rand() when it's not.
I guess if we ever really care about threading on Android we'll have to
essentially re-implement our own rand_r function with the required
looking to avoid the race, but at this point it's not really that
important (none of the bindings work on Android, so only the command
line tools may be used and none of them start containers in parallel).
--
Stéphane Graber
Ubuntu developer
http://www.ubuntu.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20130819/a400caed/attachment.pgp>
More information about the lxc-devel
mailing list