Preliminary support to intercept getrandom() #275

This commit is contained in:
Wolfgang Hommel
2020-11-15 21:57:10 +01:00
parent dacc5866a7
commit ca2f3fefa1
3 changed files with 77 additions and 1 deletions

25
test/getrandom_test.c Normal file
View File

@@ -0,0 +1,25 @@
#include <stdio.h>
#include <sys/random.h>
#include <stdlib.h>
int main(int argc, char **argv) {
char *buf = calloc(100, 1);
size_t buflen = 100;
unsigned flags = GRND_NONBLOCK;
fprintf(stdout, "Before getrandom:\n");
for (int i=0; i < buflen; i++) { fprintf(stdout, "%hhu ", buf[i]); }
fprintf(stdout, "\n");
int result = getrandom(buf, buflen, flags);
fprintf(stdout, "getrandom() result: %d\n", result);
if (result == -1) perror("getrandom() unsuccessful");
fprintf(stdout, "After getrandom:\n");
for (int i=0; i < buflen; i++) { fprintf(stdout, "%hhu ", buf[i]); }
fprintf(stdout, "\n");
free(buf);
return 0;
}