eclipse / tinydtls

Eclipse tinydtls
https://projects.eclipse.org/projects/iot.tinydtls
Other
105 stars 57 forks source link

dtls_prng_posix.c: Fix random() only support #192

Closed mrdeep1 closed 1 year ago

mrdeep1 commented 1 year ago

Use of random() requires that _GNU_SOURCE is defined. Cannot use variables named rand.

Make sure that dtls_prng.o is rebuilt whenever any of the platform-specific/dtlsprng*.c files are updated.

mrdeep1 commented 1 year ago

Issue can be reproduced (remember to do a make clean) by putting in this bad change on a Ubuntu20 system

diff --git a/platform-specific/dtls_prng_posix.c b/platform-specific/dtls_prng_posix.c
index 3c9d51f..ec3c1f9 100644
--- a/platform-specific/dtls_prng_posix.c
+++ b/platform-specific/dtls_prng_posix.c
@@ -35,7 +41,7 @@
  */
 int
 dtls_prng(unsigned char *buf, size_t len) {
-#ifdef HAVE_GETRANDOM
+#ifdef HAVE_GETRANDOM_bad_test
   return getrandom(buf, len, 0);
 #elif defined(HAVE_RANDOM)
boaks commented 1 year ago

Reproducing the issue I found, that -D_GNU_SOURCE is already used to compile the tests for posix. So I guess, this is the right solution. Hope that really works on the "old" unix, for which this "random()" was added.

LGTM