[lxc-devel] [PATCH 11/17] Use srand/rand instead of initstate/random

Daniel P. Berrange berrange at redhat.com
Fri Aug 16 16:25:34 UTC 2013


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
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|




More information about the lxc-devel mailing list