xref: /titanic_44/usr/src/test/libc-tests/tests/random/getrandred.c (revision db8b037b5616a366b7dfdc01ef9552f02f9adfdd)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2015 Joyent, Inc.
14  */
15 
16 /*
17  * Regression test for illumos#5843.
18  */
19 
20 #include <string.h>
21 #include <stdlib.h>
22 #include <sys/random.h>
23 
24 #define	NTRIES 5
25 #define	NOFF	128
26 #define	NBYTES	223
27 
28 int
29 main(void)
30 {
31 	int i;
32 	char buf[1024];
33 
34 	(void) memset(buf, 'a', sizeof (buf));
35 
36 	/*
37 	 * Try to go ahead and corrupt ourselves NTRIES times.
38 	 */
39 	for (i = 0; i < NTRIES; i++) {
40 		(void) getrandom(buf + NOFF, NBYTES, 0);
41 	}
42 
43 	for (i = 0; i < NOFF; i++) {
44 		if (buf[i] != 'a')
45 			abort();
46 	}
47 
48 	for (i = NBYTES + NOFF; i < sizeof (buf); i++) {
49 		if (buf[i] != 'a')
50 			abort();
51 	}
52 
53 	return (0);
54 }
55