Call __msan_unpoison after syscall(__NR_getrandom, ...).
MSan doesn't realize that the syscall initialized the output buffer, so
this is necessary to avoid MSan errors when generating random numbers on
Linux.
@@ -207,6 +207,12 @@ finish_random(void)
#include <unistd.h>
#include <sys/syscall.h>
+#if defined(__has_feature)
+#if __has_feature(memory_sanitizer)
+void __msan_unpoison(void *, size_t);
+#endif
+#endif
+
void
init_random(void)
{
@@ -227,6 +233,14 @@ read_random(void *buf, size_t size)
position += n;
}
}
+#if defined(__has_feature)
+#if __has_feature(memory_sanitizer)
+ /* Need to do this because MSan doesn't realize that syscall has
+ * initialized the output buffer.
+ */
+ __msan_unpoison(buf, size);
+#endif
+#endif
return;
}
