Remember that srandom() + random() will do arc4random() internally,
unless srandom_determinisitic() is called.

But I guess the idiocy is the code ahead of srandom...

Christian Weisgerber <na...@mips.inka.de> wrote:

> telephony/resiprocate fails to build on non-x86 architectures.
> 
> The reason is amazing:
> error: Need some way to seed the random number generator
> http://build-failures.rhaalovely.net/aarch64/2020-05-30/telephony/resiprocate%2C.log
> 
> The culprit is stunRand() in rutil/stun/Stun.cxx.  Depending on
> operating system and architecture, this function tries to query
> some high resolution timer or get a piece of random data, which it
> uses to seed srandom(), and then calls random().  It's an inconsistent
> mess (why build a 64-bit seed?  does it return 32 or 31 bits?).
> Oh, and it uses rdtsc on __i386__, an instruction that appeared on
> the Pentium.
> 
> I already spent too much time looking at this; here's a patch that
> simply bypasses the whole mess.
> 
> OK?
> 
> Index: Makefile
> ===================================================================
> RCS file: /cvs/ports/telephony/resiprocate/Makefile,v
> retrieving revision 1.1.1.1
> diff -u -p -r1.1.1.1 Makefile
> --- Makefile  29 May 2020 21:41:23 -0000      1.1.1.1
> +++ Makefile  4 Jun 2020 16:28:51 -0000
> @@ -6,6 +6,7 @@ COMMENT-return =      reSIProcate STUN/TURN c
>  
>  V =                  1.12.0
>  DISTNAME =           resiprocate-${V}
> +REVISION =           0
>  PKGNAME-main =               resiprocate-${V}
>  PKGNAME-repro =              resiprocate-repro-${V}
>  PKGNAME-return =     resiprocate-return-${V}
> Index: patches/patch-rutil_stun_Stun_cxx
> ===================================================================
> RCS file: patches/patch-rutil_stun_Stun_cxx
> diff -N patches/patch-rutil_stun_Stun_cxx
> --- /dev/null 1 Jan 1970 00:00:00 -0000
> +++ patches/patch-rutil_stun_Stun_cxx 4 Jun 2020 16:28:51 -0000
> @@ -0,0 +1,23 @@
> +$OpenBSD$
> +
> +Index: rutil/stun/Stun.cxx
> +--- rutil/stun/Stun.cxx.orig
> ++++ rutil/stun/Stun.cxx
> +@@ -802,6 +802,9 @@ stunRand()
> + {
> +    // return 32 bits of random stuff
> +    resip_assert( sizeof(int) == 4 );
> ++#if defined(__OpenBSD__)
> ++   return arc4random();
> ++#else
> +    static bool init=false;
> +    if ( !init )
> +    { 
> +@@ -857,6 +860,7 @@ stunRand()
> +    return ret;
> + #else
> +    return random(); 
> ++#endif
> + #endif
> + }
> + 
> -- 
> Christian "naddy" Weisgerber                          na...@mips.inka.de
> 

Reply via email to