]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
rand: fix build error with autotools + LibreSSL
authorViktor Szakats <commit@vsz.me>
Sun, 5 Nov 2023 23:27:55 +0000 (23:27 +0000)
committerViktor Szakats <commit@vsz.me>
Mon, 6 Nov 2023 10:11:56 +0000 (10:11 +0000)
autotools unexpectedly detects `arc4random` because it is also looking
into dependency libs. One dependency, LibreSSL, happens to publish an
`arc4random` function (via its shared lib before v3.7, also via static
lib as of v3.8.2). When trying to use this function in `lib/rand.c`,
its protoype is missing. To fix that, curl included a prototype, but
that used a C99 type without including `stdint.h`, causing:

```
../../lib/rand.c:37:1: error: unknown type name 'uint32_t'
   37 | uint32_t arc4random(void);
      | ^
1 error generated.
```

This patch improves this by dropping the local prototype and instead
limiting `arc4random` use for non-OpenSSL builds. OpenSSL builds provide
their own random source anyway.

The better fix would be to teach autotools to not link dependency libs
while detecting `arc4random`.

LibreSSL publishing a non-namespaced `arc4random` tracked here:
https://github.com/libressl/portable/issues/928

Regression from 755ddbe901cd0c921fbc3ac5b3775c0dc683bc73 #10672

Reviewed-by: Daniel Stenberg
Fixes #12257
Closes #12274

lib/rand.c

index 6bd96136f117ba8420c730b1505d598f6ea61444..e57ebe2a488a3927f38edfd4c37c4b0a5e43e014 100644 (file)
 #ifdef HAVE_ARPA_INET_H
 #include <arpa/inet.h>
 #endif
-#ifdef HAVE_ARC4RANDOM
-/* Some platforms might have the prototype missing (ubuntu + libressl) */
-uint32_t arc4random(void);
-#endif
 
 #include <curl/curl.h>
 #include "urldata.h"
@@ -146,7 +142,7 @@ static CURLcode randit(struct Curl_easy *data, unsigned int *rnd)
   }
 #endif
 
-#ifdef HAVE_ARC4RANDOM
+#if defined(HAVE_ARC4RANDOM) && !defined(USE_OPENSSL)
   *rnd = (unsigned int)arc4random();
   return CURLE_OK;
 #endif