File tree Expand file tree Collapse file tree 3 files changed +55
-0
lines changed
regression/cbmc-library/getrandom-01 Expand file tree Collapse file tree 3 files changed +55
-0
lines changed Original file line number Diff line number Diff line change 1+ #ifdef __linux__
2+ # include <sys/random.h>
3+
4+ # include <assert.h>
5+
6+ int main ()
7+ {
8+ char zero_bytes [6 ] = {0 };
9+ ssize_t res = getrandom (zero_bytes , 5 , 0 );
10+ assert (res <= 5 );
11+ assert (zero_bytes [5 ] == 0 );
12+ return 0 ;
13+ }
14+ #else
15+ int main ()
16+ {
17+ }
18+ #endif
Original file line number Diff line number Diff line change 1+ CORE
2+ main.c
3+ --pointer-check --bounds-check --signed-overflow-check
4+ ^EXIT=0$
5+ ^SIGNAL=0$
6+ ^VERIFICATION SUCCESSFUL$
7+ --
8+ ^warning: ignoring
Original file line number Diff line number Diff line change 1+ /* FUNCTION: getrandom */
2+
3+ #ifdef __linux__
4+
5+ # ifndef __CPROVER_SYS_RANDOM_H_INCLUDED
6+ # include <sys/random.h>
7+ # define __CPROVER_SYS_RANDOM_H_INCLUDED
8+ # endif
9+
10+ # ifndef GRND_NONBLOCK
11+ # define GRND_NONBLOCK 0
12+ # endif
13+
14+ __CPROVER_bool __VERIFIER_nondet___CPROVER_bool ();
15+
16+ ssize_t getrandom (void * buf , size_t buflen , unsigned int flags )
17+ {
18+ if (flags & GRND_NONBLOCK && __VERIFIER_nondet___CPROVER_bool ())
19+ return -1 ;
20+
21+ char bytes [buflen ];
22+ __CPROVER_array_replace (buf , bytes );
23+
24+ size_t actual_bytes ;
25+ __CPROVER_assume (actual_bytes <= buflen );
26+ return (ssize_t )actual_bytes ;
27+ }
28+
29+ #endif
You can’t perform that action at this time.
0 commit comments