Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH] zsh/random module [UPDATED]



On 11/24/2022 4:07 AM, nimaje+zml@xxxxxxxxxxxxxx wrote:


On 11/24/22 03:58, Clinton Bunch wrote:
[snip]
+/**/
+int
+setup_(UNUSED(Module m))
+{
+#ifdef USE_URANDOM
+    /* Check for the existence of /dev/urandom */
+
+    struct stat st;
+
+    if (lstat("/dev/urandom",&st) < 0) {
Why not stat()?
Is it appropriate for /dev/urandom to be a symlink?

Yes, for example that is the case on freebsd where urandom is just a symlink to random for compatibility with programs that expect urandom to be there (random blocks until the randomness pool is seeded and then doesn't block anymore).
On FreeBSD it doesn't use urandom, so it didn't show up in my testing.  It only uses urandom if arc4random() or getrandom() doesn't exist


+    zwarn("No kernel random pool found.");
+    return 1;
+    }
+
+    if (!(S_ISCHR(st.st_mode)) ) {
+    zwarn("No kernel random pool found.");
+    return 1;
+    }

So this check would be wrong on freebsd (or use random directly and give an option to use urandom on systems where random starts to block for some reason after being seeded, but no idea if there is a good reason for random being a symlink).
On most systems random is defined to block if the randomness pool falls below a certain threshold until more random data is available

[snip]






Messages sorted by: Reverse Date, Date, Thread, Author