Skip to contentSkip to conversation

Bug report - Solaris 11.3 conflicting types for 'random_get_bytes'

PATCH Applied Sad Clouds 3 participants 3 messages Nov 1, 2020 – Nov 3, 2020

Subsystems (2)
lore
Share & tools
lore

Sad Clouds

author
#0 lore raw

mcookie fails to build on Solaris 11.3 since it already has random_get_bytes() function with a different signature. Please rename it to something different.

===> Building for mcookie-2.32.1
/opt/pkg/bin/bmake all-recursive
Making all in po
CC lib/libcommon_la-randutils.lo
In file included from lib/randutils.c:29:
/usr/include/sys/random.h:71:12: error: conflicting types for 'random_get_bytes'

   71 | extern int random_get_bytes(uint8_t *dbuf, size_t dlen);
      |            ^~~~~~~~~~~~~~~~
In file included from lib/randutils.c:19:
./include/randutils.h:14:13: note: previous declaration of 'random_get_bytes' was here
   14 | extern void random_get_bytes(void *buf, size_t nbytes);
      |             ^~~~~~~~~~~~~~~~

*** [lib/libcommon_la-randutils.lo] Error code 1

bmake[2]: stopped in /opt/pkgbuild/objects/x11/mcookie/work/util-linux-2.32.1

#1 lore raw

PATCH 1/1 lib/randutils: rename random_get_bytes()

Rename random_get_bytes() to avoid colliding a Solaris library function that has the same name.

Reference: https://lore.kernel.org/util-linux/[email protected]/
Reference: https://blogs.oracle.com/solaris/solaris-random-number-generation-v2

---
 include/randutils.h    | 2 +-
 lib/randutils.c        | 6 +++---
 libfdisk/src/dos.c     | 2 +-
 libuuid/src/gen_uuid.c | 6 +++---
 misc-utils/mcookie.c   | 2 +-
 sys-utils/ipcmk.c      | 6 +++---
 6 files changed, 12 insertions(+), 12 deletions(-)
include/randutils.h +1 -1
index 86e35f3f4..5b863d04c 100644
@@ -11,7 +11,7 @@ extern int rand_get_number(int low_n, int high_n);
 
 /* /dev/urandom based with fallback to rand() */
 extern int random_get_fd(void);
-extern void random_get_bytes(void *buf, size_t nbytes);
+extern void ul_random_get_bytes(void *buf, size_t nbytes);
 extern const char *random_tell_source(void);
 
 #endif
lib/randutils.c +3 -3
index 84c002187..bf8193338 100644
@@ -102,7 +102,7 @@ int random_get_fd(void)
 #define UL_RAND_READ_ATTEMPTS	8
 #define UL_RAND_READ_DELAY	125000	/* microseconds */
 
-void random_get_bytes(void *buf, size_t nbytes)
+void ul_random_get_bytes(void *buf, size_t nbytes)
 {
 	unsigned char *cp = (unsigned char *)buf;
 	size_t i, n = nbytes;
@@ -216,7 +216,7 @@ int main(int argc, char *argv[])
 
 	printf("Multiple random calls:\n");
 	for (i = 0; i < n; i++) {
-		random_get_bytes(&v, sizeof(v));
+		ul_random_get_bytes(&v, sizeof(v));
 		printf("#%02zu: %25"PRIu64"\n", i, v);
 	}
 
@@ -227,7 +227,7 @@ int main(int argc, char *argv[])
 	if (!buf)
 		err(EXIT_FAILURE, "failed to allocate buffer");
 
-	random_get_bytes(buf, bufsz);
+	ul_random_get_bytes(buf, bufsz);
 	for (i = 0; i < n; i++) {
 		vp = (int64_t *) (buf + (i * sizeof(*vp)));
 		printf("#%02zu: %25"PRIu64"\n", i, *vp);
libfdisk/src/dos.c +1 -1
index 890e33a26..82ccb6940 100644
@@ -693,7 +693,7 @@ static int dos_create_disklabel(struct fdisk_context *cxt)
 	/* random disk signature */
 	if (!has_id) {
 		DBG(LABEL, ul_debug("DOS: generate new ID"));
-		random_get_bytes(&id, sizeof(id));
+		ul_random_get_bytes(&id, sizeof(id));
 	}
 
 	if (fdisk_has_protected_bootbits(cxt))
libuuid/src/gen_uuid.c +3 -3
index 69f9591a4..50039fc2e 100644
@@ -275,7 +275,7 @@ static int get_clock(uint32_t *clock_high, uint32_t *clock_low,
 	}
 
 	if ((last.tv_sec == 0) && (last.tv_usec == 0)) {
-		random_get_bytes(&clock_seq, sizeof(clock_seq));
+		ul_random_get_bytes(&clock_seq, sizeof(clock_seq));
 		clock_seq &= 0x3FFF;
 		gettimeofday(&last, NULL);
 		last.tv_sec--;
@@ -413,7 +413,7 @@ int __uuid_generate_time(uuid_t out, int *num)
 
 	if (!has_init) {
 		if (get_node_id(node_id) <= 0) {
-			random_get_bytes(node_id, 6);
+			ul_random_get_bytes(node_id, 6);
 			/*
 			 * Set multicast bit, to prevent conflicts
 			 * with IEEE 802 addresses obtained from
@@ -511,7 +511,7 @@ void __uuid_generate_random(uuid_t out, int *num)
 		n = *num;
 
 	for (i = 0; i < n; i++) {
-		random_get_bytes(buf, sizeof(buf));
+		ul_random_get_bytes(buf, sizeof(buf));
 		uuid_unpack(buf, &uu);
 
 		uu.clock_seq = (uu.clock_seq & 0x3FFF) | 0x8000;
misc-utils/mcookie.c +1 -1
index 549531454..315740127 100644
@@ -184,7 +184,7 @@ int main(int argc, char **argv)
 	randomness_from_files(&ctl);
 	free(ctl.files);
 
-	random_get_bytes(&buf, RAND_BYTES);
+	ul_random_get_bytes(&buf, RAND_BYTES);
 	ul_MD5Update(&ctl.ctx, buf, RAND_BYTES);
 	if (ctl.verbose)
 		fprintf(stderr, P_("Got %d byte from %s\n",
sys-utils/ipcmk.c +3 -3
index 5e942b775..0a84be77e 100644
@@ -40,7 +40,7 @@ static int create_shm(size_t size, int permission)
 {
 	key_t key;
 
-	random_get_bytes(&key, sizeof(key));
+	ul_random_get_bytes(&key, sizeof(key));
 	return shmget(key, size, permission | IPC_CREAT);
 }
 
@@ -48,7 +48,7 @@ static int create_msg(int permission)
 {
 	key_t key;
 
-	random_get_bytes(&key, sizeof(key));
+	ul_random_get_bytes(&key, sizeof(key));
 	return msgget(key, permission | IPC_CREAT);
 }
 
@@ -56,7 +56,7 @@ static int create_sem(int nsems, int permission)
 {
 	key_t key;
 
-	random_get_bytes(&key, sizeof(key));
+	ul_random_get_bytes(&key, sizeof(key));
 	return semget(key, nsems, permission | IPC_CREAT);
 }
 
Signature · 1 line
2.29.2
maintainer Applied
#2 lore raw

Re: [PATCH] lib/randutils: rename random_get_bytes()

Quoted 7 lines · Sami Kerola
 include/randutils.h    | 2 +-
 lib/randutils.c        | 6 +++---
 libfdisk/src/dos.c     | 2 +-
 libuuid/src/gen_uuid.c | 6 +++---
 misc-utils/mcookie.c   | 2 +-
 sys-utils/ipcmk.c      | 6 +++---
 6 files changed, 12 insertions(+), 12 deletions(-)

Applied, thanks.

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com